4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include "libcmdutils.h"
39 * Returns the status of attempting to obtain the extended system
40 * attributes in the specified view.
42 * Note: If obtaining status for an extended attribute file, the caller must
43 * chdir into the hidden directory prior to calling sysattr_status().
45 * Returns 1 if the extended system attributes were obtained, otherwise
49 sysattr_status(char *file
, xattr_view_t view
)
51 nvlist_t
*response
= NULL
;
55 status
= getattrat(AT_FDCWD
, view
, file
, &response
);
59 (void) nvlist_free(response
);
66 * Returns the type of the specified in file. If the file name matches
67 * the name of either a read-only or read-write extended system attribute
68 * file then sysattr_type() returns the type of file:
69 * return value file type
70 * ------------ ---------
71 * _RO_SATTR read-only extended system attribute file
72 * _RW_SATTR read-write extended system attribute file
73 * _NOT_SATTR neither a read-only or read-write extended system
77 sysattr_type(char *file
)
84 if (strcmp(basename(file
), file
) != 0) {
90 if (strcmp(file
, VIEW_READONLY
) == 0) {
92 } else if (strcmp(file
, VIEW_READWRITE
) == 0) {
100 * Call sysattr_support() instead of pathconf(file, _PC_SATTR_ENABLED) or
101 * pathconf(file, _PC_SATTR_EXISTS) so that if pathconf() fails over NFS, we
102 * can still try to figure out if extended system attributes are supported by
103 * testing for a valid extended system attribute file.
105 * 'name' can have the values _PC_SATTR_ENABLED or _PC_SATTR_EXISTS.
107 * Returns 1 if the underlying file system supports extended system attributes,
108 * otherwise, returns -1.
111 sysattr_support(char *file
, int name
)
116 if ((name
!= _PC_SATTR_ENABLED
) &&
117 (name
!= _PC_SATTR_EXISTS
)) {
121 if (((rc
= pathconf(file
, name
)) == 1) || (errno
!= EINVAL
)) {
124 return (sysattr_status(file
, XATTR_VIEW_READONLY
));