xref: /titanic_50/usr/src/common/xattr/xattr_common.c (revision fd9ee8b58485b20072eeef1310a88ff348d5e7fa)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/attr.h>
26 #if defined(_KERNEL)
27 #include <sys/systm.h>
28 #else
29 #include <strings.h>
30 #endif
31 
32 /*
33  * This table maps each system attribute to its option and its view.
34  * All new system attrs must be added to this table.  To add a new view,
35  * add another entry to xattr_dirents[] and update xattr_view_t in sys/attr.h.
36  * Also, xattr_file_pathconf() and sys/unistd.h should be updated to add
37  * return values for the new view.
38  */
39 
40 static xattr_entry_t xattrs[F_ATTR_ALL] = {
41 	{ A_ARCHIVE, O_ARCHIVE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
42 	{ A_HIDDEN, O_HIDDEN, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
43 	{ A_READONLY, O_READONLY, XATTR_VIEW_READWRITE,
44 	    DATA_TYPE_BOOLEAN_VALUE },
45 	{ A_SYSTEM, O_SYSTEM, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
46 	{ A_APPENDONLY, O_APPENDONLY, XATTR_VIEW_READWRITE,
47 	    DATA_TYPE_BOOLEAN_VALUE },
48 	{ A_NODUMP, O_NODUMP, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
49 	{ A_IMMUTABLE, O_IMMUTABLE, XATTR_VIEW_READWRITE,
50 	    DATA_TYPE_BOOLEAN_VALUE },
51 	{ A_AV_MODIFIED, O_AV_MODIFIED, XATTR_VIEW_READWRITE,
52 	    DATA_TYPE_BOOLEAN_VALUE },
53 	{ A_OPAQUE, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_BOOLEAN_VALUE },
54 	{ A_AV_SCANSTAMP, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT8_ARRAY },
55 	{ A_AV_QUARANTINED, O_AV_QUARANTINED, XATTR_VIEW_READWRITE,
56 	    DATA_TYPE_BOOLEAN_VALUE },
57 	{ A_NOUNLINK, O_NOUNLINK, XATTR_VIEW_READWRITE,
58 	    DATA_TYPE_BOOLEAN_VALUE },
59 	{ A_CRTIME, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_UINT64_ARRAY },
60 	{ A_OWNERSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
61 	{ A_GROUPSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
62 	{ A_FSID, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT64 },
63 	{ A_REPARSE_POINT, O_REPARSE_POINT, XATTR_VIEW_READONLY,
64 	    DATA_TYPE_BOOLEAN_VALUE },
65 	{ A_GEN, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT64 },
66 	{ A_OFFLINE, O_OFFLINE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
67 	{ A_SPARSE, O_SPARSE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
68 };
69 
70 const char *
71 attr_to_name(f_attr_t attr)
72 {
73 	if (attr >= F_ATTR_ALL || attr < 0)
74 		return (NULL);
75 
76 	return (xattrs[attr].x_name);
77 }
78 
79 const char *
80 attr_to_option(f_attr_t attr)
81 {
82 	if (attr >= F_ATTR_ALL || attr < 0)
83 		return (NULL);
84 
85 	return (xattrs[attr].x_option);
86 }
87 
88 f_attr_t
89 name_to_attr(const char *name)
90 {
91 	int i;
92 
93 	for (i = 0; i < F_ATTR_ALL; i++) {
94 		if (strcmp(name, xattrs[i].x_name) == 0)
95 			return (i);
96 	}
97 
98 	return (F_ATTR_INVAL);
99 }
100 
101 f_attr_t
102 option_to_attr(const char *option)
103 {
104 	int i;
105 
106 	for (i = 0; i < F_ATTR_ALL; i++) {
107 		if (strcmp(option, xattrs[i].x_option) == 0)
108 			return (i);
109 	}
110 
111 	return (F_ATTR_INVAL);
112 }
113 
114 xattr_view_t
115 attr_to_xattr_view(f_attr_t attr)
116 {
117 	if (attr >= F_ATTR_ALL || attr < 0)
118 		return (NULL);
119 
120 	return (xattrs[attr].x_xattr_view);
121 }
122 
123 int
124 attr_count(void)
125 {
126 	return (F_ATTR_ALL);
127 }
128 
129 data_type_t
130 attr_to_data_type(f_attr_t attr)
131 {
132 	if (attr >= F_ATTR_ALL || attr < 0)
133 		return (DATA_TYPE_UNKNOWN);
134 
135 	return (xattrs[attr].x_data_type);
136 }
137