Update of /cvsroot/file-extattr/File-ExtAttr In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv8257 Modified Files: MANIFEST portable.h Added Files: extattr_bsd.h extattr_linux.h extattr_macosx.h extattr_os.h extattr_solaris.c extattr_solaris.h Log Message: Initial Solaris 10 support; almost works ;) --- NEW FILE: extattr_solaris.h --- #ifndef EXTATTR_SOLARIS_H #define EXTATTR_SOLARIS_H #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> /* * XXX: FIXME: Need to distinguish file non-existence and attribute * non-existence. Need to choose an unused error code somehow. */ #ifndef ENOATTR #define ENOATTR ENOENT #endif int solaris_setxattr (const char *path, const char *attrname, const char *attrvalue, const size_t slen, const int flags); int solaris_fsetxattr (const int fd, const char *attrname, const char *attrvalue, const size_t slen, const int flags); int solaris_getxattr (const char *path, const char *attrname, void *attrvalue, const size_t slen); int solaris_fgetxattr (const int fd, const char *attrname, void *attrvalue, const size_t slen); int solaris_removexattr (const char *path, const char *attrname); int solaris_fremovexattr (const int fd, const char *attrname); #endif /* EXTATTR_SOLARIS_H */ --- NEW FILE: extattr_solaris.c --- #include "extattr_os.h" #ifdef EXTATTR_SOLARIS #include <errno.h> #include <unistd.h> static const mode_t ATTRMODE = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP; static inline int writexattr (const int attrfd, const char *attrvalue, const size_t slen) { int ok = 1; if (ftruncate(attrfd, 0) == -1) ok = 0; if (ok && (write(attrfd, attrvalue, slen) != slen)) ok = 0; return ok ? 0 : -1; } static inline int readclose (const int attrfd, void *attrvalue, const size_t slen) { int sz = 0; int saved_errno = 0; int ok = 1; if (attrfd == -1) ok = 0; if (ok) { if (slen) { sz = read(attrfd, attrvalue, slen); } else { /* Request to see how much data is there. */ struct stat sbuf; if (fstat(attrfd, &sbuf) == 0) sz = sbuf.st_size; else sz = -1; } if (sz == -1) ok = 0; } if (!ok) saved_errno = errno; if ((attrfd >= 0) && (close(attrfd) == -1) && !saved_errno) saved_errno = errno; if (saved_errno) errno = saved_errno; return ok ? sz : -1; } static inline int unlinkclose (const int attrdirfd, const char *attrname) { int sz = 0; int saved_errno = 0; int ok = 1; if (attrdirfd == -1) ok = 0; if (ok && (unlinkat(attrdirfd, attrname, 0) == -1)) ok = 0; if (!ok) saved_errno = errno; if ((attrdirfd >= 0) && (close(attrdirfd) == -1) && !saved_errno) saved_errno = errno; if (saved_errno) errno = saved_errno; return ok ? sz : -1; } int solaris_setxattr (const char *path, const char *attrname, const char *attrvalue, const size_t slen, const int flags) { /* XXX: Support overwrite/no overwrite flags */ int saved_errno = 0; int ok = 1; int attrfd = attropen(path, attrname, O_RDWR|O_CREAT, ATTRMODE); /* XXX: More common code? */ if (attrfd == -1) ok = 0; if (ok && (writexattr(attrfd, attrvalue, slen) == -1)) ok = 0; if (!ok) saved_errno = errno; if ((attrfd >= 0) && (close(attrfd) == -1) && !saved_errno) saved_errno = errno; if (saved_errno) errno = saved_errno; return ok ? 0 : -1; } int solaris_fsetxattr (const int fd, const char *attrname, const char *attrvalue, const size_t slen, const int flags) { /* XXX: Support overwrite/no overwrite flags */ int saved_errno = 0; int ok = 1; int attrfd = openat(fd, attrname, O_RDWR|O_CREAT|O_XATTR, ATTRMODE); /* XXX: More common code? */ if (attrfd == -1) ok = 0; if (ok && (writexattr(attrfd, attrvalue, slen) == -1)) ok = 0; if (!ok) saved_errno = errno; if ((attrfd >= 0) && (close(attrfd) == -1) && !saved_errno) saved_errno = errno; if (saved_errno) errno = saved_errno; return ok ? 0 : -1; } int solaris_getxattr (const char *path, const char *attrname, void *attrvalue, const size_t slen) { const int attrfd = attropen(path, attrname, O_RDONLY); return readclose(attrfd, attrvalue, slen); } int solaris_fgetxattr (const int fd, const char *attrname, void *attrvalue, const size_t slen) { int attrfd = openat(fd, attrname, O_RDONLY|O_XATTR); return readclose(attrfd, attrvalue, slen); } int solaris_removexattr (const char *path, const char *attrname) { int attrdirfd = attropen(path, ".", O_RDONLY); return unlinkclose(attrdirfd, attrname); } int solaris_fremovexattr (const int fd, const char *attrname) { int attrdirfd = openat(fd, ".", O_RDONLY|O_XATTR); return unlinkclose(attrdirfd, attrname); } #endif /* EXTATTR_SOLARIS */ --- NEW FILE: extattr_macosx.h --- #ifndef EXTATTR_MACOSX_H #define EXTATTR_MACOSX_H #include <sys/types.h> #include <sys/xattr.h> #endif /* EXTATTR_MACOSX_H */ --- NEW FILE: extattr_bsd.h --- #ifndef EXTATTR_BSD_H #define EXTATTR_BSD_H #include <sys/types.h> #include <sys/extattr.h> #include <sys/uio.h> /* Helper to convert number of bytes written into success/failure code. */ static inline int bsd_extattr_set_succeeded (const int expected, const int actual) { int ret = -1; if (actual != -1) { if (actual != expected) { errno = ENOBUFS; /* Pretend there's not enough space for the data. */ ret = -1; } else { ret = 0; } } return ret; } static inline int bsd_setxattr (const char *path, const char *attrname, const char *attrvalue, const size_t slen) { /* XXX: Namespace? */ int ret = extattr_set_file(path, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); return bsd_extattr_set_succeeded(slen, ret); } static inline int bsd_fsetxattr (const int fd, const char *attrname, const char *attrvalue, const size_t slen) { /* XXX: Namespace? */ int ret = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); return bsd_extattr_set_succeeded(slen, ret); } #endif /* EXTATTR_BSD_H */ --- NEW FILE: extattr_os.h --- #ifndef EXTATTR_OS_H #define EXTATTR_OS_H /* OS detection */ #ifdef BSD #define EXTATTR_BSD #endif #ifdef __APPLE__ #define EXTATTR_MACOSX #endif #if defined(sun) || defined(__sun) #if defined(__SVR4) || defined(__svr4__) #define EXTATTR_SOLARIS #endif #endif /* Include appropriate header for this OS, defaulting to Linux-style */ #ifdef EXTATTR_BSD #include "extattr_bsd.h" #elif defined(EXTATTR_MACOSX) #include "extattr_macosx.h" #elif defined(EXTATTR_SOLARIS) #include "extattr_solaris.h" #else #include "extattr_linux.h" #endif #endif Index: portable.h =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/portable.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** portable.h 6 Mar 2006 20:29:14 -0000 1.4 --- portable.h 14 Aug 2006 21:10:54 -0000 1.5 *************** *** 2,42 **** #define EXTATTR_PORTABLE_H ! #include <sys/types.h> ! #ifdef __APPLE__ ! #include <sys/xattr.h> ! #elif defined(BSD) /* FreeBSD, NetBSD, OpenBSD */ ! #include <sys/extattr.h> ! #include <sys/uio.h> ! #else /* Linux */ ! #include <attr/attributes.h> ! #include <attr/xattr.h> ! #endif ! ! #ifdef BSD ! ! /* Helper to convert number of bytes written into success/failure code. */ ! static inline int ! bsd_extattr_set_succeeded (const int expected, const int actual) ! { ! int ret = -1; ! ! if (actual != -1) ! { ! if (actual != expected) ! { ! errno = ENOBUFS; /* Pretend there's not enough space for the data. */ ! ret = -1; ! } ! else ! { ! ret = 0; ! } ! } ! ! return ret; ! } ! ! #endif /* BSD */ static inline int portable_setxattr (const char *path, --- 2,9 ---- #define EXTATTR_PORTABLE_H ! /* OS detection */ ! #include "extattr_os.h" + /* Portable extattr functions */ static inline int portable_setxattr (const char *path, *************** *** 46,55 **** const int flags) { ! #ifdef __APPLE__ return setxattr(path, attrname, attrvalue, slen, 0, flags); ! #elif defined(BSD) ! /* XXX: Namespace? */ ! int ret = extattr_set_file(path, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); ! return bsd_extattr_set_succeeded(slen, ret); #else return setxattr(path, attrname, attrvalue, slen, flags); --- 13,22 ---- const int flags) { ! #ifdef EXTATTR_MACOSX return setxattr(path, attrname, attrvalue, slen, 0, flags); ! #elif defined(EXTATTR_BSD) ! return bsd_setxattr(path, attrname, attrvalue, slen); ! #elif defined(EXTATTR_SOLARIS) ! return solaris_setxattr(path, attrname, attrvalue, slen, flags); #else return setxattr(path, attrname, attrvalue, slen, flags); *************** *** 64,73 **** const int flags) { ! #ifdef __APPLE__ return fsetxattr(fd, attrname, attrvalue, slen, 0, flags); ! #elif defined(BSD) ! /* XXX: Namespace? */ ! int ret = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); ! return bsd_extattr_set_succeeded(slen, ret); #else return fsetxattr(fd, attrname, attrvalue, slen, flags); --- 31,40 ---- const int flags) { ! #ifdef EXTATTR_MACOSX return fsetxattr(fd, attrname, attrvalue, slen, 0, flags); ! #elif defined(EXTATTR_BSD) ! return bsd_fsetxattr(fd, attrname, attrvalue, slen); ! #elif defined(EXTATTR_SOLARIS) ! return solaris_fsetxattr(fd, attrname, attrvalue, slen, flags); #else return fsetxattr(fd, attrname, attrvalue, slen, flags); *************** *** 81,89 **** const size_t slen) { ! #ifdef __APPLE__ return getxattr(path, attrname, attrvalue, slen, 0, 0); ! #elif defined(BSD) /* XXX: Namespace? */ return extattr_get_file(path, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); #else return getxattr(path, attrname, attrvalue, slen); --- 48,58 ---- const size_t slen) { ! #ifdef EXTATTR_MACOSX return getxattr(path, attrname, attrvalue, slen, 0, 0); ! #elif defined(EXTATTR_BSD) /* XXX: Namespace? */ return extattr_get_file(path, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); + #elif defined(EXTATTR_SOLARIS) + return solaris_getxattr(path, attrname, attrvalue, slen); #else return getxattr(path, attrname, attrvalue, slen); *************** *** 97,105 **** const size_t slen) { ! #ifdef __APPLE__ return fgetxattr(fd, attrname, attrvalue, slen, 0, 0); ! #elif defined(BSD) /* XXX: Namespace? */ return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); #else return fgetxattr(fd, attrname, attrvalue, slen); --- 66,76 ---- const size_t slen) { ! #ifdef EXTATTR_MACOSX return fgetxattr(fd, attrname, attrvalue, slen, 0, 0); ! #elif defined(EXTATTR_BSD) /* XXX: Namespace? */ return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, attrname, attrvalue, slen); + #elif defined(EXTATTR_SOLARIS) + return solaris_fgetxattr(fd, attrname, attrvalue, slen); #else return fgetxattr(fd, attrname, attrvalue, slen); *************** *** 114,117 **** --- 85,89 ---- return extattr_get_file(path, EXTATTR_NAMESPACE_USER, attrname, NULL, 0); #else + /* XXX: Can BSD use this too? Maybe once namespacing sorted. */ return portable_getxattr(path, attrname, NULL, 0); #endif *************** *** 125,128 **** --- 97,101 ---- return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, attrname, NULL, 0); #else + /* XXX: Can BSD use this too? Maybe once namespacing sorted. */ return portable_fgetxattr(fd, attrname, NULL, 0); #endif *************** *** 132,140 **** portable_removexattr (const char *path, const char *name) { ! #ifdef __APPLE__ return removexattr(path, name, 0); ! #elif defined(BSD) /* XXX: Namespace? */ return extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name); #else return removexattr(path, name); --- 105,115 ---- portable_removexattr (const char *path, const char *name) { ! #ifdef EXTATTR_MACOSX return removexattr(path, name, 0); ! #elif defined(EXTATTR_BSD) /* XXX: Namespace? */ return extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name); + #elif defined(EXTATTR_SOLARIS) + return solaris_removexattr(path, name); #else return removexattr(path, name); *************** *** 145,153 **** portable_fremovexattr (const int fd, const char *name) { ! #ifdef __APPLE__ return fremovexattr(fd, name, 0); ! #elif defined(BSD) /* XXX: Namespace? */ return extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, name); #else return fremovexattr(fd, name); --- 120,130 ---- portable_fremovexattr (const int fd, const char *name) { ! #ifdef EXTATTR_MACOSX return fremovexattr(fd, name, 0); ! #elif defined(EXTATTR_BSD) /* XXX: Namespace? */ return extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, name); + #elif defined(EXTATTR_SOLARIS) + return solaris_fremovexattr(fd, name); #else return fremovexattr(fd, name); *************** *** 158,163 **** portable_listxattr(const char *path, char *buf, const size_t slen) { ! #ifdef __APPLE__ return listxattr(path, buf, slen, 0); #else return listxattr(path, buf, slen); --- 135,144 ---- portable_listxattr(const char *path, char *buf, const size_t slen) { ! #ifdef EXTATTR_MACOSX return listxattr(path, buf, slen, 0); + #elif defined(EXTATTR_BSD) + #error "FIXME" + #elif defined(EXTATTR_SOLARIS) + /*#error "XXX: FIXME"*/ #else return listxattr(path, buf, slen); *************** *** 168,173 **** portable_flistxattr(const int fd, char *buf, const size_t slen) { ! #ifdef __APPLE__ return flistxattr(fd, buf, slen, 0); #else return flistxattr(fd, buf, slen); --- 149,158 ---- portable_flistxattr(const int fd, char *buf, const size_t slen) { ! #ifdef EXTATTR_MACOSX return flistxattr(fd, buf, slen, 0); + #elif defined(EXTATTR_BSD) + #error "FIXME" + #elif defined(EXTATTR_SOLARIS) + /*#error "XXX: FIXME" */ #else return flistxattr(fd, buf, slen); Index: MANIFEST =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/MANIFEST,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MANIFEST 27 May 2006 11:54:16 -0000 1.9 --- MANIFEST 14 Aug 2006 21:10:54 -0000 1.10 *************** *** 10,13 **** --- 10,19 ---- helpers.h helpers.c + extattr_bsd.h + extattr_linux.h + extattr_macosx.h + extattr_os.h + extattr_solaris.c + extattr_solaris.h t/00load.t t/01distribution.t --- NEW FILE: extattr_linux.h --- #ifndef EXTATTR_LINUX_H #define EXTATTR_LINUX_H #include <sys/types.h> #include <attr/attributes.h> #include <attr/xattr.h> #endif /* EXTATTR_LINUX_H */ |