コード例 #1
0
ファイル: xattr.c プロジェクト: rchicoli/samba
ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size)
{
#if defined(HAVE_FGETXATTR)
#ifndef XATTR_ADDITIONAL_OPTIONS
	return fgetxattr(filedes, name, value, size);
#else

/* So that we do not recursivly call this function */
#undef fgetxattr
	int options = 0;
	return fgetxattr(filedes, name, value, size, 0, options);
#endif
#elif defined(HAVE_FGETEA)
	return fgetea(filedes, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FD)
	char *s;
	ssize_t retval;
	int attrnamespace = (strncmp(name, "system", 6) == 0) ? 
		EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
	const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;

	if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
		if (size == 0) {
			return retval;
		} else if (retval > size) {
			errno = ERANGE;
			return -1;
		}
		if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
			return retval;
	}

	return -1;
#elif defined(HAVE_ATTR_GETF)
	int retval, flags = 0;
	int valuelength = (int)size;
	char *attrname = strchr(name,'.') + 1;

	if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;

	retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
	if (size == 0 && retval == -1 && errno == E2BIG) {
		return valuelength;
	}
	return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
	ssize_t ret = -1;
	int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
	if (attrfd >= 0) {
		ret = solaris_read_xattr(attrfd, value, size);
		close(attrfd);
	}
	return ret;
#else
	errno = ENOSYS;
	return -1;
#endif
}
コード例 #2
0
ファイル: extattr.c プロジェクト: Distrotech/netatalk
ssize_t sys_fgetxattr (int filedes, const char *uname, void *value, size_t size)
{
    const char *name = prefix(uname);

#if defined(HAVE_FGETXATTR)
#ifndef XATTR_ADD_OPT
    return fgetxattr(filedes, name, value, size);
#else
    int options = 0;
    return fgetxattr(filedes, name, value, size, 0, options);
#endif
#elif defined(HAVE_FGETEA)
    return fgetea(filedes, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FD)
    char *s;
    ssize_t retval;
    int attrnamespace = (strncmp(name, "system", 6) == 0) ? 
        EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
    const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;

    if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
        if(retval > size) {
            errno = ERANGE;
            return -1;
        }
        if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
            return retval;
    }

    LOG(log_debug, logtype_default, "sys_fgetxattr: extattr_get_fd(): %s", strerror(errno));
    return -1;
#elif defined(HAVE_ATTR_GETF)
    int retval, flags = 0;
    int valuelength = (int)size;
    char *attrname = strchr(name,'.') + 1;

    if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;

    retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);

    return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
    ssize_t ret = -1;
    int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
    if (attrfd >= 0) {
        ret = solaris_read_xattr(attrfd, value, size);
        close(attrfd);
    }
    return ret;
#else
    errno = ENOSYS;
    return -1;
#endif
}
コード例 #3
0
ファイル: system.c プロジェクト: WiseMan787/ralink_sdk
ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
{
#if defined(HAVE_FGETXATTR)
	return fgetxattr(filedes, name, value, size);
#elif defined(HAVE_ATTR_GETF)
	int retval, flags = 0;
	int valuelength = (int)size;
	char *attrname = strchr(name,'.') +1;
	
	if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;

	retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);

	return retval ? retval : valuelength;
#else
	errno = ENOSYS;
	return -1;
#endif
}
コード例 #4
0
ファイル: hsmapi.c プロジェクト: crossmeta/sgi
extern int
HsmInitFileContext(
	hsm_f_ctxt_t	*contextp,
const	xfs_bstat_t	*statp)
{
	dmf_f_ctxt_t	*dmf_f_ctxtp = (dmf_f_ctxt_t *)contextp;
	XFSattrvalue1_t	*dmfattrp;
	int		attrlen;
	void		*hanp;
	size_t		hlen;
	dm_ino_t	ino;
	dm_igen_t	igen;
	int		fd;
	int		error;

	dmf_f_ctxtp->candidate = 0; /* assume file will NOT be of interest */

	/* Try and rule out a dualstate inode by doing some quick tests. */

	if ((statp->bs_mode & S_IFMT) != S_IFREG) {
		return 0;	/* not a regular file */
	}
	if ((statp->bs_xflags & XFS_XFLAG_HASATTR) == 0) {
		return 0;	/* no DMF attribute exists */
	}
	if ((statp->bs_dmevmask & DUALSTATE_BITS) != DUALSTATE_BITS) {
		return 0;	/* non-dualstate managed region bits */
	}

	/* We have a likely candidate, so we have to pay the price and look
	   for the DMF attribute.  (It could be in a disk block separate from
	   the inode.)
	*/

	ino = (dm_ino_t)statp->bs_ino;
	igen = (dm_igen_t)statp->bs_gen;
	if (dm_make_handle(&dmf_f_ctxtp->fsys.fsid, &ino, &igen, &hanp, &hlen) != 0) {
		return 0;	/* can't make a proper handle */
	}

	/* The following code should eventually be replaced with the
	   attr_multif-by-handle call when it is available.
	*/

	fd = open_by_handle(hanp, hlen, O_RDONLY);
	dm_handle_free(hanp, hlen);
	if (fd < 0) {
                return 0;
	}
	attrlen = sizeof(dmf_f_ctxtp->attrval);
	error = attr_getf(fd, DMF_ATTR_NAME, dmf_f_ctxtp->attrval,
		&attrlen, ATTR_ROOT);
	(void)close(fd);
	if (error) {
		return 0;
 	}

	if (attrlen != DMF_ATTR_LEN) {
                return 0;	/* not the right length to be the attribute */
	}

	dmfattrp = (XFSattrvalue1_t *)dmf_f_ctxtp->attrval;
	if (dmfattrp->version != XFS_ATTR_VERSION_1) {
		return 0;	/* we don't support this version */
	}
	if (dmfattrp->state[0] != '\0') {
		return 0;	/* should be zero */
	}
	if (dmfattrp->state[1] != DMF_ST_DUALSTATE &&
	    dmfattrp->state[1] != DMF_ST_UNMIGRATING) {
		return 0;
	}

	/* We have a DMF dual state file. */

	dmf_f_ctxtp->candidate = 1;
	dmf_f_ctxtp->filesize = BTOBB(statp->bs_size);
	return 0;
}