From 4ecc13c0acdb12b0a4bf22d0077406e0840679db Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 24 Aug 2020 16:50:18 +0300 Subject: [PATCH] Replace ENODATA with ENOATTR in xattrs functions for macOS builds. The contract in macOS xattr functions is to return ENOATTR when an extended attribute cannot be found. --- include/ntfs-3g/compat.h | 10 ++++++++++ src/lowntfs-3g.c | 10 +++++----- src/ntfs-3g.c | 10 +++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/ntfs-3g/compat.h b/include/ntfs-3g/compat.h index fa57a38a..288a86a2 100644 --- a/include/ntfs-3g/compat.h +++ b/include/ntfs-3g/compat.h @@ -46,6 +46,16 @@ #define ELIBACC ENOENT #endif +/* xattr APIs in macOS differs from Linux ones in that they expect the special + * error code ENOATTR to be returned when an attribute cannot be found. So + * define NTFS_NOXATTR_ERRNO to the appropriate "no xattr found" errno value for + * the platform. */ +#if defined(__APPLE__) || defined(__DARWIN__) +#define NTFS_NOXATTR_ERRNO ENOATTR +#else +#define NTFS_NOXATTR_ERRNO ENODATA +#endif + #ifndef PATH_MAX #define PATH_MAX 4096 #endif diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 7d5c3e8f..1e7098ef 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -3465,7 +3465,7 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, /* trusted only readable by root */ if ((namespace == XATTRNS_TRUSTED) && security.uid) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto out; } #endif @@ -3476,7 +3476,7 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, } /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } /* otherwise file must be readable */ @@ -3493,7 +3493,7 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } rsize = na->data_size; @@ -3704,7 +3704,7 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, } if (!na) { if (flags == XATTR_REPLACE) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } if (ntfs_attr_add(ni, AT_DATA, lename, lename_len, NULL, 0)) { @@ -3942,7 +3942,7 @@ static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *na } if (ntfs_attr_remove(ni, AT_DATA, lename, lename_len)) { if (errno == ENOENT) - errno = ENODATA; + errno = NTFS_NOXATTR_ERRNO; res = -errno; } if (!res) { diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 6e0d688c..d3537660 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -3236,14 +3236,14 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, /* trusted only readable by root */ if ((namespace == XATTRNS_TRUSTED) && security.uid) - return -ENODATA; + return -NTFS_NOXATTR_ERRNO; #endif ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; /* Return with no result for symlinks, fifo, etc. */ if (!user_xattrs_allowed(ctx, ni)) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } /* otherwise file must be readable */ @@ -3260,7 +3260,7 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, } na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); if (!na) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } rsize = na->data_size; @@ -3450,7 +3450,7 @@ static int ntfs_fuse_setxattr(const char *path, const char *name, } if (!na) { if (flags == XATTR_REPLACE) { - res = -ENODATA; + res = -NTFS_NOXATTR_ERRNO; goto exit; } if (ntfs_attr_add(ni, AT_DATA, lename, lename_len, NULL, 0)) { @@ -3680,7 +3680,7 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) } if (ntfs_attr_remove(ni, AT_DATA, lename, lename_len)) { if (errno == ENOENT) - errno = ENODATA; + errno = NTFS_NOXATTR_ERRNO; res = -errno; } if (!res) {