X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fxattr.c;h=2b4882a0de0982b52e35c0527dec9b238d83066d;hp=a5169cfbafbf659896e5600150ea1e8ccd22bdbb;hb=ceb3a57f67f33b33c1f6cafdd0ef81808273f0c0;hpb=9ff99418361cd1b56b00e4ffef52444021e60c72 diff --git a/daemon/xattr.c b/daemon/xattr.c index a5169cf..2b4882a 100644 --- a/daemon/xattr.c +++ b/daemon/xattr.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -405,28 +405,6 @@ do_lxattrlist (const char *path, char *const *names) } } - /* If verbose, debug what we're about to send back. */ - if (verbose) { - fprintf (stderr, "lxattrlist: returning: [\n"); - for (k = 0; k < ret->guestfs_int_xattr_list_len; ++k) { - const guestfs_int_xattr *entry = &ret->guestfs_int_xattr_list_val[k]; - if (STRNEQ (entry[0].attrname, "")) { - fprintf (stderr, "ERROR: expecting empty attrname at k = %zu\n", k); - break; - } - fprintf (stderr, " %zu: special attrval = %s\n", - k, entry[0].attrval.attrval_val); - for (i = 1; k+i < ret->guestfs_int_xattr_list_len; ++i) { - if (STREQ (entry[i].attrname, "")) - break; - fprintf (stderr, " name %s, value length %d\n", - entry[i].attrname, entry[i].attrval.attrval_len); - } - k += i-1; - } - fprintf (stderr, "]\n"); - } - return ret; error: @@ -448,6 +426,90 @@ do_lxattrlist (const char *path, char *const *names) #endif } +char * +do_getxattr (const char *path, const char *name, size_t *size_r) +{ + ssize_t r; + char *buf; + size_t len; + + CHROOT_IN; + r = getxattr (path, name, NULL, 0); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("getxattr"); + return NULL; + } + + len = r; + buf = malloc (len); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + CHROOT_IN; + r = getxattr (path, name, buf, len); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("getxattr"); + free (buf); + return NULL; + } + + if (len != (size_t) r) { + reply_with_error ("getxattr: unexpected size (%zu/%zd)", len, r); + free (buf); + return NULL; + } + + /* Must set size_r last thing before returning. */ + *size_r = len; + return buf; /* caller frees */ +} + +char * +do_lgetxattr (const char *path, const char *name, size_t *size_r) +{ + ssize_t r; + char *buf; + size_t len; + + CHROOT_IN; + r = lgetxattr (path, name, NULL, 0); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("lgetxattr"); + return NULL; + } + + len = r; + buf = malloc (len); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + CHROOT_IN; + r = lgetxattr (path, name, buf, len); + CHROOT_OUT; + if (r == -1) { + reply_with_perror ("lgetxattr"); + free (buf); + return NULL; + } + + if (len != (size_t) r) { + reply_with_error ("lgetxattr: unexpected size (%zu/%zd)", len, r); + free (buf); + return NULL; + } + + /* Must set size_r last thing before returning. */ + *size_r = len; + return buf; /* caller frees */ +} + #else /* no xattr.h */ int optgroup_linuxxattrs_available (void) @@ -497,4 +559,16 @@ do_lxattrlist (const char *path, char *const *names) NOT_AVAILABLE (NULL); } +char * +do_getxattr (const char *path, const char *name, size_t *size_r) +{ + NOT_AVAILABLE (NULL); +} + +char * +do_lgetxattr (const char *path, const char *name, size_t *size_r) +{ + NOT_AVAILABLE (NULL); +} + #endif /* no xattr.h */