xref: /titanic_51/usr/src/common/xattr/xattr_common.c (revision 7a286c471efbab8562f7655a82931904703fffe0)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
22*7a286c47SDai Ngo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #include <sys/attr.h>
27da6c28aaSamw #if defined(_KERNEL)
28da6c28aaSamw #include <sys/systm.h>
29da6c28aaSamw #else
30da6c28aaSamw #include <strings.h>
31da6c28aaSamw #endif
32da6c28aaSamw 
33da6c28aaSamw /*
34da6c28aaSamw  * This table maps each system attribute to its option and its view.
35da6c28aaSamw  * All new system attrs must be added to this table.  To add a new view,
36da6c28aaSamw  * add another entry to xattr_dirents[] and update xattr_view_t in sys/attr.h.
37da6c28aaSamw  * Also, xattr_file_pathconf() and sys/unistd.h should be updated to add
38da6c28aaSamw  * return values for the new view.
39da6c28aaSamw  */
40da6c28aaSamw 
41da6c28aaSamw static xattr_entry_t xattrs[F_ATTR_ALL] = {
42da6c28aaSamw 	{ A_ARCHIVE, O_ARCHIVE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
43da6c28aaSamw 	{ A_HIDDEN, O_HIDDEN, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
44da6c28aaSamw 	{ A_READONLY, O_READONLY, XATTR_VIEW_READWRITE,
45da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
46da6c28aaSamw 	{ A_SYSTEM, O_SYSTEM, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
47da6c28aaSamw 	{ A_APPENDONLY, O_APPENDONLY, XATTR_VIEW_READWRITE,
48da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
49da6c28aaSamw 	{ A_NODUMP, O_NODUMP, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
50da6c28aaSamw 	{ A_IMMUTABLE, O_IMMUTABLE, XATTR_VIEW_READWRITE,
51da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
52da6c28aaSamw 	{ A_AV_MODIFIED, O_AV_MODIFIED, XATTR_VIEW_READWRITE,
53da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
54da6c28aaSamw 	{ A_OPAQUE, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_BOOLEAN_VALUE },
55da6c28aaSamw 	{ A_AV_SCANSTAMP, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT8_ARRAY },
56da6c28aaSamw 	{ A_AV_QUARANTINED, O_AV_QUARANTINED, XATTR_VIEW_READWRITE,
57da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
58da6c28aaSamw 	{ A_NOUNLINK, O_NOUNLINK, XATTR_VIEW_READWRITE,
59da6c28aaSamw 	    DATA_TYPE_BOOLEAN_VALUE },
60da6c28aaSamw 	{ A_CRTIME, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_UINT64_ARRAY },
61da6c28aaSamw 	{ A_OWNERSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
62da6c28aaSamw 	{ A_GROUPSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
63da6c28aaSamw 	{ A_FSID, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT64 },
64*7a286c47SDai Ngo 	{ A_REPARSE_POINT, O_REPARSE_POINT, XATTR_VIEW_READONLY,
65*7a286c47SDai Ngo 	    DATA_TYPE_BOOLEAN_VALUE },
66da6c28aaSamw };
67da6c28aaSamw 
68da6c28aaSamw const char *
69da6c28aaSamw attr_to_name(f_attr_t attr)
70da6c28aaSamw {
71da6c28aaSamw 	if (attr >= F_ATTR_ALL || attr < 0)
72da6c28aaSamw 		return (NULL);
73da6c28aaSamw 
74da6c28aaSamw 	return (xattrs[attr].x_name);
75da6c28aaSamw }
76da6c28aaSamw 
77da6c28aaSamw const char *
78da6c28aaSamw attr_to_option(f_attr_t attr)
79da6c28aaSamw {
80da6c28aaSamw 	if (attr >= F_ATTR_ALL || attr < 0)
81da6c28aaSamw 		return (NULL);
82da6c28aaSamw 
83da6c28aaSamw 	return (xattrs[attr].x_option);
84da6c28aaSamw }
85da6c28aaSamw 
86da6c28aaSamw f_attr_t
87da6c28aaSamw name_to_attr(const char *name)
88da6c28aaSamw {
89da6c28aaSamw 	int i;
90da6c28aaSamw 
91da6c28aaSamw 	for (i = 0; i < F_ATTR_ALL; i++) {
92da6c28aaSamw 		if (strcmp(name, xattrs[i].x_name) == 0)
93da6c28aaSamw 			return (i);
94da6c28aaSamw 	}
95da6c28aaSamw 
96da6c28aaSamw 	return (F_ATTR_INVAL);
97da6c28aaSamw }
98da6c28aaSamw 
99da6c28aaSamw f_attr_t
100da6c28aaSamw option_to_attr(const char *option)
101da6c28aaSamw {
102da6c28aaSamw 	int i;
103da6c28aaSamw 
104da6c28aaSamw 	for (i = 0; i < F_ATTR_ALL; i++) {
105da6c28aaSamw 		if (strcmp(option, xattrs[i].x_option) == 0)
106da6c28aaSamw 			return (i);
107da6c28aaSamw 	}
108da6c28aaSamw 
109da6c28aaSamw 	return (F_ATTR_INVAL);
110da6c28aaSamw }
111da6c28aaSamw 
112da6c28aaSamw xattr_view_t
113da6c28aaSamw attr_to_xattr_view(f_attr_t attr)
114da6c28aaSamw {
115da6c28aaSamw 	if (attr >= F_ATTR_ALL || attr < 0)
116da6c28aaSamw 		return (NULL);
117da6c28aaSamw 
118da6c28aaSamw 	return (xattrs[attr].x_xattr_view);
119da6c28aaSamw }
120da6c28aaSamw 
121da6c28aaSamw int
122da6c28aaSamw attr_count(void)
123da6c28aaSamw {
124da6c28aaSamw 	return (F_ATTR_ALL);
125da6c28aaSamw }
126da6c28aaSamw 
127da6c28aaSamw data_type_t
128da6c28aaSamw attr_to_data_type(f_attr_t attr)
129da6c28aaSamw {
130da6c28aaSamw 	if (attr >= F_ATTR_ALL || attr < 0)
131da6c28aaSamw 		return (DATA_TYPE_UNKNOWN);
132da6c28aaSamw 
133da6c28aaSamw 	return (xattrs[attr].x_data_type);
134da6c28aaSamw }
135