da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7257d1b4d25bfac0c802847390e98a464fd787acraf#include "lint.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <errno.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <fcntl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <mtlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <attr.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/types.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/syscall.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/stat.h>
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner#include <sys/file.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <unistd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <dlfcn.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdio.h>
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf#include <atomic.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int (*nvpacker)(nvlist_t *, char **, size_t *, int, int);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int (*nvsize)(nvlist_t *, size_t *, int);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int (*nvunpacker)(char *, size_t, nvlist_t **);
d8ac9b2d669163fee52330a52017528035cacb4emarksstatic int (*nvfree)(nvlist_t *);
d8ac9b2d669163fee52330a52017528035cacb4emarksstatic int (*nvlookupint64)(nvlist_t *, const char *, uint64_t *);
d8ac9b2d669163fee52330a52017528035cacb4emarks
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic mutex_t attrlock = DEFAULTMUTEX;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int initialized;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char *xattr_view_name[XATTR_VIEW_LAST] = {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw VIEW_READONLY,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw VIEW_READWRITE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulknerint
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner__openattrdirat(int fd, const char *name)
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner{
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner return (syscall(SYS_openat, fd, name, FXATTRDIROPEN, 0));
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner}
8fd04b8338ed5093ec2d1e668fa620b7de44c177Roger A. Faulkner
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwattrat_init()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *packer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *sizer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *unpacker;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *freer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *looker;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (initialized == 0) {
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf void *handle = dlopen("libnvpair.so.1", RTLD_LAZY);
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf if (handle == NULL ||
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf (packer = dlsym(handle, "nvlist_pack")) == NULL ||
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf (sizer = dlsym(handle, "nvlist_size")) == NULL ||
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf (unpacker = dlsym(handle, "nvlist_unpack")) == NULL ||
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf (freer = dlsym(handle, "nvlist_free")) == NULL ||
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf (looker = dlsym(handle, "nvlist_lookup_uint64")) == NULL) {
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf if (handle)
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) dlclose(handle);
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf return (-1);
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf }
f90fe29e0aba2450cb7153602766438d44fbdf42raf
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw lmutex_lock(&attrlock);
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf if (initialized != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw lmutex_unlock(&attrlock);
5ad42b1b1469908fabc0099764182e9ecbc04ddaSurya Prakki (void) dlclose(handle);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf nvpacker = (int (*)(nvlist_t *, char **, size_t *, int, int))
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf packer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf nvsize = (int (*)(nvlist_t *, size_t *, int))
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf sizer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf nvunpacker = (int (*)(char *, size_t, nvlist_t **))
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf unpacker;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf nvfree = (int (*)(nvlist_t *))
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf freer;
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf nvlookupint64 = (int (*)(nvlist_t *, const char *, uint64_t *))
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf looker;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8cd45542f2a452ca0dab13d8b2d5cfa876ccbebcraf membar_producer();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw initialized = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw lmutex_unlock(&attrlock);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwattr_nv_pack(nvlist_t *request, void **nv_request, size_t *nv_requestlen)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t bufsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *packbuf = NULL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (nvsize(request, &bufsize, NV_ENCODE_XDR) != 0) {
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks errno = EINVAL;
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw packbuf = malloc(bufsize);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (packbuf == NULL)
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (nvpacker(request, &packbuf, &bufsize, NV_ENCODE_XDR, 0) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(packbuf);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks errno = EINVAL;
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *nv_request = (void *)packbuf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *nv_requestlen = bufsize;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic const char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwview_to_name(xattr_view_t view)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (view >= XATTR_VIEW_LAST || view < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattr_view_name[view]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwxattr_openat(int basefd, xattr_view_t view, int mode)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *xattrname;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int xattrfd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int oflag;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (view) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case XATTR_VIEW_READONLY:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw oflag = O_RDONLY;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case XATTR_VIEW_READWRITE:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw oflag = mode & O_RDWR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks errno = EINVAL;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (mode & O_XATTR)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw oflag |= O_XATTR;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xattrname = view_to_name(view);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xattrfd = openat(basefd, xattrname, oflag);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (xattrfd < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Don't cache sysattr info (advisory) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) directio(xattrfd, DIRECTIO_ON);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwcgetattr(int fd, nvlist_t **response)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int bytesread;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void *nv_response;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t nv_responselen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct stat buf;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (error = attrat_init())
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((error = fstat(fd, &buf)) != 0)
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw nv_responselen = buf.st_size;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((nv_response = malloc(nv_responselen)) == NULL)
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bytesread = read(fd, nv_response, nv_responselen);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks if (bytesread != nv_responselen) {
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks free(nv_response);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks errno = EFAULT;
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks }
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks if (nvunpacker(nv_response, nv_responselen, response)) {
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks free(nv_response);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks errno = ENOMEM;
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(nv_response);
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwcsetattr(int fd, nvlist_t *request)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error, saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int byteswritten;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void *nv_request;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t nv_requestlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (error = attrat_init())
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((error = attr_nv_pack(request, &nv_request, &nv_requestlen)) != 0)
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw byteswritten = write(fd, nv_request, nv_requestlen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (byteswritten != nv_requestlen) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(nv_request);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
575bd8a230f2c20b1878ebb473c30a12f0eb1b2emarks return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(nv_request);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfgetattr(int basefd, xattr_view_t view, nvlist_t **response)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error, saveerrno, xattrfd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((xattrfd = xattr_openat(basefd, view, O_XATTR)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error = cgetattr(xattrfd, response);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwfsetattr(int basefd, xattr_view_t view, nvlist_t *request)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error, saveerrno, xattrfd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((xattrfd = xattr_openat(basefd, view, O_RDWR | O_XATTR)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error = csetattr(xattrfd, request);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwgetattrat(int basefd, xattr_view_t view, const char *name, nvlist_t **response)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error, saveerrno, namefd, xattrfd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((namefd = __openattrdirat(basefd, name)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((xattrfd = xattr_openat(namefd, view, 0)) < 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error = cgetattr(xattrfd, response);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsetattrat(int basefd, xattr_view_t view, const char *name, nvlist_t *request)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int error, saveerrno, namefd, xattrfd;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((namefd = __openattrdirat(basefd, name)) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((xattrfd = xattr_openat(namefd, view, O_RDWR)) < 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error = csetattr(xattrfd, request);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saveerrno = errno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(namefd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) close(xattrfd);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw errno = saveerrno;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
d8ac9b2d669163fee52330a52017528035cacb4emarks
d8ac9b2d669163fee52330a52017528035cacb4emarksvoid
d8ac9b2d669163fee52330a52017528035cacb4emarkslibc_nvlist_free(nvlist_t *nvp)
d8ac9b2d669163fee52330a52017528035cacb4emarks{
d8ac9b2d669163fee52330a52017528035cacb4emarks nvfree(nvp);
d8ac9b2d669163fee52330a52017528035cacb4emarks}
d8ac9b2d669163fee52330a52017528035cacb4emarks
d8ac9b2d669163fee52330a52017528035cacb4emarksint
d8ac9b2d669163fee52330a52017528035cacb4emarkslibc_nvlist_lookup_uint64(nvlist_t *nvp, const char *name, uint64_t *value)
d8ac9b2d669163fee52330a52017528035cacb4emarks{
d8ac9b2d669163fee52330a52017528035cacb4emarks return (nvlookupint64(nvp, name, value));
d8ac9b2d669163fee52330a52017528035cacb4emarks}