summaryrefslogtreecommitdiff
path: root/usr/src/common/xattr/xattr_common.c
blob: e9b511bd996a682c2141dc55d034d762780dbbc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#include <sys/attr.h>
#if defined(_KERNEL)
#include <sys/systm.h>
#else
#include <strings.h>
#endif

/*
 * This table maps each system attribute to its option and its view.
 * All new system attrs must be added to this table.  To add a new view,
 * add another entry to xattr_dirents[] and update xattr_view_t in sys/attr.h.
 * Also, xattr_file_pathconf() and sys/unistd.h should be updated to add
 * return values for the new view.
 */

static xattr_entry_t xattrs[F_ATTR_ALL] = {
	{ A_ARCHIVE, O_ARCHIVE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
	{ A_HIDDEN, O_HIDDEN, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
	{ A_READONLY, O_READONLY, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_SYSTEM, O_SYSTEM, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
	{ A_APPENDONLY, O_APPENDONLY, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_NODUMP, O_NODUMP, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
	{ A_IMMUTABLE, O_IMMUTABLE, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_AV_MODIFIED, O_AV_MODIFIED, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_OPAQUE, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_BOOLEAN_VALUE },
	{ A_AV_SCANSTAMP, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT8_ARRAY },
	{ A_AV_QUARANTINED, O_AV_QUARANTINED, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_NOUNLINK, O_NOUNLINK, XATTR_VIEW_READWRITE,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_CRTIME, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_UINT64_ARRAY },
	{ A_OWNERSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
	{ A_GROUPSID, O_NONE, XATTR_VIEW_READWRITE, DATA_TYPE_NVLIST },
	{ A_FSID, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT64 },
	{ A_REPARSE_POINT, O_REPARSE_POINT, XATTR_VIEW_READONLY,
	    DATA_TYPE_BOOLEAN_VALUE },
	{ A_GEN, O_NONE, XATTR_VIEW_READONLY, DATA_TYPE_UINT64 },
	{ A_OFFLINE, O_OFFLINE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
	{ A_SPARSE, O_SPARSE, XATTR_VIEW_READWRITE, DATA_TYPE_BOOLEAN_VALUE },
};

const char *
attr_to_name(f_attr_t attr)
{
	if (attr >= F_ATTR_ALL || attr < 0)
		return (NULL);

	return (xattrs[attr].x_name);
}

const char *
attr_to_option(f_attr_t attr)
{
	if (attr >= F_ATTR_ALL || attr < 0)
		return (NULL);

	return (xattrs[attr].x_option);
}

f_attr_t
name_to_attr(const char *name)
{
	int i;

	for (i = 0; i < F_ATTR_ALL; i++) {
		if (strcmp(name, xattrs[i].x_name) == 0)
			return (i);
	}

	return (F_ATTR_INVAL);
}

f_attr_t
option_to_attr(const char *option)
{
	int i;

	for (i = 0; i < F_ATTR_ALL; i++) {
		if (strcmp(option, xattrs[i].x_option) == 0)
			return (i);
	}

	return (F_ATTR_INVAL);
}

xattr_view_t
attr_to_xattr_view(f_attr_t attr)
{
	if (attr >= F_ATTR_ALL || attr < 0)
		return (XATTR_VIEW_INVALID);

	return (xattrs[attr].x_xattr_view);
}

int
attr_count(void)
{
	return (F_ATTR_ALL);
}

data_type_t
attr_to_data_type(f_attr_t attr)
{
	if (attr >= F_ATTR_ALL || attr < 0)
		return (DATA_TYPE_UNKNOWN);

	return (xattrs[attr].x_data_type);
}