int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
int sys_copyxattr (const char *src, const char *dst);
-int sys_getxattrfd(const char *path, const char *uname, int oflag, ...);
+int sys_getxattrfd(int fd, const char *uname, int oflag, ...);
/****************************************************************************************
* Stuff for our implementation of storing EAs in files in .AppleDouble dirs
{
EC_INIT;
- LOG(log_debug, logtype_default, "set_lock(%s, %s, off: %jd (%s), len: %jd): BEGIN",
- cmd == F_SETLK ? "F_SETLK" : "F_GETLK",
+ LOG(log_debug, logtype_default, "set_lock(fd: %d, %s, %s, off: %jd (%s), len: %jd): BEGIN",
+ fd, cmd == F_SETLK ? "F_SETLK" : "F_GETLK",
lock->l_type == F_RDLCK ? "F_RDLCK" : lock->l_type == F_WRLCK ? "F_WRLCK" : "F_UNLCK",
(intmax_t)lock->l_start,
shmdstrfromoff(lock->l_start),
return 0;
}
- EC_NEG1_LOGSTR( fcntl(fd, cmd, lock),
- "set_lock: %s", strerror(errno));
+ EC_NEG1_LOG( fcntl(fd, cmd, lock) );
EC_CLEANUP:
EC_EXIT;
#include <atalk/adouble.h>
-/* this is so that we can keep lists of fds referencing the same file
- * around. that way, we can honor locks created by the same process
+/* this is so that we can keep lists of fds referencing the same file
+ * around. that way, we can honor locks created by the same process
* with the same file. */
#define adf_lock_init(a) do { \
break; \
for (i = 0; i < (a)->adf_lockcount; i++) { \
adf_lock_t *lock = (a)->adf_lock + i; \
- if (--(*lock->refcount) < 1)free(lock->refcount); \
+ if (--(*lock->refcount) < 1) \
+ free(lock->refcount); \
} \
free((a)->adf_lock); \
adf_lock_init(a); \
LOG(log_debug, logtype_default, "ad_reso_size(\"%s\")", path);
#ifdef HAVE_EAFD
- int opened = 0;
- int eafd = ad_reso_fileno(ad);
- if (eafd == -1) {
- EC_NEG1( eafd = sys_getxattrfd(path, AD_EA_RESO, O_RDONLY) );
- opened = 1;
- }
- EC_NEG1( fstat(eafd, &st) );
- ad->ad_rlen = st.st_size;
+ ssize_t easz;
+ int eafd;
+
+ if ((eafd = ad_reso_fileno(ad)) == -1)
+ if ((eafd = ad_data_fileno(ad)) == -1)
+ EC_FAIL;
+
+ EC_NEG1( easz = sys_fgetxattr(eafd, AD_EA_RESO, NULL, 0) );
+ ad->ad_rlen = easz;
#else
const char *rfpath;
EC_NULL_LOG( rfpath = ad->ad_ops->ad_path(path, adflags));
LOG(log_debug, logtype_default, "ad_reso_size(\"%s\"): size: %zd", path, ad->ad_rlen);
EC_CLEANUP:
-#ifdef HAVE_EAFD
- if (opened)
- close(eafd);
-#endif
if (ret != 0)
ad->ad_rlen = 0;
EC_EXIT;
goto EC_CLEANUP;
}
#ifdef HAVE_EAFD
- if ((ad_reso_fileno(ad) = sys_getxattrfd(path, AD_EA_RESO, oflags)) == -1) {
- if (!(adflags & ADFLAGS_CREATE))
+ if (ad_meta_fileno(ad) == -1)
+ EC_FAIL;
+ if ((ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad), AD_EA_RESO, oflags)) == -1) {
+ if (!(adflags & ADFLAGS_CREATE)) {
+ errno = ENOENT;
EC_FAIL;
+ }
oflags |= O_CREAT;
- EC_NEG1_LOG( ad_reso_fileno(ad) = sys_getxattrfd(path, AD_EA_RESO, oflags, 0666) );
+ EC_NEG1_LOG( ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad),
+ AD_EA_RESO, oflags, 0666) );
}
#else
EC_NULL_LOG( rfpath = ad->ad_ops->ad_path(path, adflags) );
#endif
}
-int sys_getxattrfd(const char *path, const char *uname, int oflag, ...)
+int sys_getxattrfd(int fd, const char *uname, int oflag, ...)
{
#if defined HAVE_ATTROPEN
int eafd;
va_list args;
- mode_t mode;
+ mode_t mode = 0;
if (oflag & O_CREAT) {
va_start(args, oflag);
}
if (oflag & O_CREAT)
- eafd = attropen(path, uname, oflag, mode);
+ eafd = solaris_openat(fd, uname, oflag | O_XATTR, mode);
else
- eafd = attropen(path, uname, oflag);
+ eafd = solaris_openat(fd, uname, oflag | O_XATTR, mode);
return eafd;
#else