Adding XATTR support for Free/NetBSD
Timur I. Bakeyev
timur at com.bat.ru
Wed May 24 10:11:38 GMT 2006
Hi all!
I'm trying to add XATTR support to the Samba4 code for Free/NetBSD. It's
quite easy with current architecture, but I'd like to hear your comments
about putting code the way that better fits Samba4 code guidance.
This is a sample code and possibly doesn't work, but shows the layout
I'm proposing.
With regards,
Timur.
-------------- next part --------------
--- ntvfs/posix/xattr_system.c.orig Sat Apr 22 01:48:02 2006
+++ ntvfs/posix/xattr_system.c Sat Apr 22 02:43:12 2006
@@ -35,7 +35,7 @@
size_t estimated_size,
DATA_BLOB *blob)
{
-#if HAVE_XATTR_SUPPORT
+#if defined(HAVE_XATTR_SUPPORT)
int ret;
*blob = data_blob_talloc(mem_ctx, NULL, estimated_size+16);
@@ -68,6 +68,42 @@
blob->length = ret;
return NT_STATUS_OK;
+#elif defined(HAVE_EXTATTR_SUPPORT)
+ char *s;
+ ssize_t ret;
+ int attrnamespace = (strncmp(attr_name, "system", 6) == 0) ?
+ EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
+ const char *attrname = ((s=strchr_m(attr_name, '.')) == NULL) ? attr_name : s + 1;
+ /* Estimate necessary storage size */
+ if (fd != -1) {
+ ret = extattr_get_fd(fd, attrnamespace, attrname, NULL, 0);
+ } else {
+ ret = extattr_get_file(fname, attrnamespace, attrname, NULL, 0);
+ }
+ /* Increase it, if necessary */
+ if(ret > estimated_size) {
+ estimated_size = ret;
+ }
+
+ *blob = data_blob_talloc(mem_ctx, NULL, estimated_size+16);
+ if (blob->data == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (fd != -1) {
+ ret = extattr_get_fd(fd, attrnamespace, attrname, blob->data, estimated_size);
+ } else {
+ ret = extattr_get_file(fname, attrnamespace, attrname, blob->data, estimated_size);
+ }
+
+ if (ret < 0) {
+ data_blob_free(blob);
+ return pvfs_map_errno(pvfs, errno);
+ }
+
+ blob->length = ret;
+
+ return NT_STATUS_OK;
#else
return NT_STATUS_NOT_SUPPORTED;
#endif
@@ -82,7 +118,7 @@
int fd,
const DATA_BLOB *blob)
{
-#if HAVE_XATTR_SUPPORT
+#if defined(HAVE_XATTR_SUPPORT)
int ret;
if (fd != -1) {
@@ -95,6 +131,24 @@
}
return NT_STATUS_OK;
+#elif defined(HAVE_EXTATTR_SUPPORT)
+ char *s;
+ int ret = 0;
+ int attrnamespace = (strncmp(attr_name, "system", 6) == 0) ?
+ EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
+ const char *attrname = ((s=strchr_m(attr_name, '.')) == NULL) ? attr_name : s + 1;
+
+ if (fd != -1) {
+ ret = extattr_set_fd(fd, attrnamespace, attrname, blob->data, blob->length);
+ } else {
+ ret = extattr_set_file(fname, attrnamespace, attrname, blob->data, blob->length);
+ }
+
+ if (ret < 0) {
+ return pvfs_map_errno(pvfs, errno);
+ }
+
+ return NT_STATUS_OK;
#else
return NT_STATUS_NOT_SUPPORTED;
#endif
@@ -107,7 +161,7 @@
NTSTATUS delete_xattr_system(struct pvfs_state *pvfs, const char *attr_name,
const char *fname, int fd)
{
-#if HAVE_XATTR_SUPPORT
+#if defined(HAVE_XATTR_SUPPORT)
int ret;
if (fd != -1) {
@@ -116,6 +170,24 @@
ret = removexattr(fname, attr_name);
}
if (ret == -1) {
+ return pvfs_map_errno(pvfs, errno);
+ }
+
+ return NT_STATUS_OK;
+#elif defined(HAVE_EXTATTR_SUPPORT)
+ char *s;
+ int ret = 0;
+ int attrnamespace = (strncmp(attr_name, "system", 6) == 0) ?
+ EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
+ const char *attrname = ((s=strchr_m(attr_name, '.')) == NULL) ? attr_name : s + 1;
+
+ if (fd != -1) {
+ ret = extattr_delete_fd(fd, attrnamespace, attrname);
+ } else {
+ ret = extattr_delete_file(fname, attrnamespace, attrname);
+ }
+
+ if (ret < 0) {
return pvfs_map_errno(pvfs, errno);
}
-------------- next part --------------
--- ntvfs/posix/config.m4.orig Sun May 7 01:08:48 2006
+++ ntvfs/posix/config.m4 Sun May 7 01:50:03 2006
@@ -33,6 +33,24 @@
SMB_ENABLE(XATTR,YES)
fi
+dnl ############################################
+dnl do we have sufficient extattr support for posix xattr backend
+AC_CHECK_HEADERS(sys/extattr.h sys/uio.h)
+# Check if we have extattr
+case "$host_os" in
+ *freebsd4* | *dragonfly* )
+ AC_DEFINE(BROKEN_EXTATTR, 1, [Have broken extattr API])
+ ;;
+ *)
+ AC_CHECK_FUNC_EXT(extattr_list_file)
+ ;;
+esac
+
+if test x"$ac_cv_func_ext_extattr_list_file" = x"yes"; then
+ AC_DEFINE(HAVE_EXTATTR_SUPPORT,1,[Whether we have extattr support])
+ SMB_ENABLE(XATTR,YES)
+fi
+
AC_CHECK_HEADERS(blkid/blkid.h)
AC_SEARCH_LIBS_EXT(blkid_get_cache, [blkid], BLKID_LIBS)
AC_CHECK_FUNC_EXT(blkid_get_cache, $BLKID_LIBS)
More information about the samba-technical
mailing list