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