dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libcmdutils / common / sysattrs.c
blob39b41e7b6545fe55fd570fbf558b3a91bfda47b8
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <libgen.h>
33 #include <attr.h>
34 #include <fcntl.h>
35 #include <errno.h>
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
46 * returns 0.
48 int
49 sysattr_status(char *file, xattr_view_t view)
51 nvlist_t *response = NULL;
52 int saveerrno;
53 int status;
55 status = getattrat(AT_FDCWD, view, file, &response);
57 saveerrno = errno;
58 if (response)
59 (void) nvlist_free(response);
60 errno = saveerrno;
62 return (status == 0);
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
74 * attribute file.
76 int
77 sysattr_type(char *file)
79 if (file == NULL) {
80 errno = ENOENT;
81 return (_NOT_SATTR);
84 if (strcmp(basename(file), file) != 0) {
85 errno = EINVAL;
86 return (_NOT_SATTR);
89 errno = 0;
90 if (strcmp(file, VIEW_READONLY) == 0) {
91 return (_RO_SATTR);
92 } else if (strcmp(file, VIEW_READWRITE) == 0) {
93 return (_RW_SATTR);
94 } else {
95 return (_NOT_SATTR);
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)
113 int rc;
115 errno = 0;
116 if ((name != _PC_SATTR_ENABLED) &&
117 (name != _PC_SATTR_EXISTS)) {
118 errno = EINVAL;
119 return (-1);
121 if (((rc = pathconf(file, name)) == 1) || (errno != EINVAL)) {
122 return (rc);
124 return (sysattr_status(file, XATTR_VIEW_READONLY));