X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fxattr.c;h=cb700d77702dd8a77c002c4494a7cf0267cb05bf;hb=2972987d0257d9c3d26b53f961e802d121b436cd;hp=6d356faa9ed70635d1a1c42341716564ebdd62f4;hpb=e9c37113104c1cfb234535adc9b52ad3880a41ce;p=libguestfs.git diff --git a/daemon/xattr.c b/daemon/xattr.c index 6d356fa..cb700d7 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 @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -21,7 +21,7 @@ #include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #include "actions.h" #include "optgroups.h" @@ -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 */