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