2 .\" Copyright 2014 Nexenta Systems, Inc. All rights reserved.
3 .\" Copyright (c) 2008, Sun Microsystems Inc. All Rights Reserved.
4 .\" 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.
5 .\" 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.
6 .\" 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]
7 .TH FGETATTR 3C "Nov 24, 2014"
9 fgetattr, fsetattr, getattrat, setattrat \- get and set system attributes
14 #include <sys/types.h>
16 #include <sys/nvpair.h>
18 \fBint\fR \fBfgetattr\fR(\fBint\fR fildes, \fBxattr_view_t\fR view,\fBnvlist_t **\fRresponse);
23 \fBint\fR \fBfsetattr\fR(\fBint\fR fildes, \fBxattr_view_t\fR view,\fBnvlist_t *\fRrequest)
28 \fBint\fR \fBgetattrat\fR(\fBint\fR fildes, \fBxattr_view_t\fR view, \fBconst char *\fRfilename,
29 \fBnvlist_t **\fRresponse);
34 \fBint\fR \fBsetattrat\fR(\fBint\fR fildes, \fBxattr_view_t\fR view, \fBconst char *\fRfilename,
35 \fBnvlist_t *\fRrequest);
40 The \fBfgetattr()\fR function obtains an nvlist of system attribute information
41 about an open file object specified by the file descriptor \fIfildes\fR,
42 obtained from a successful \fBopen\fR(2), \fBcreat\fR(2), \fBdup\fR(2),
43 \fBfcntl\fR(2), or \fBpipe\fR(2) function.
46 The \fBgetattrat()\fR function first opens the extended attribute file
47 specified by \fIfilename\fR in the already opened file directory object
48 specified by \fIfildes\fR. It then retrieves an nvlist of system attributes and
49 their values from \fIfilename\fR.
52 The \fIresponse\fR argument is allocated by either \fBfgetattr()\fR or
53 \fBgetattrat()\fR. The application must call \fBnvlist_free\fR(3NVPAIR) to
54 deallocate the memory.
57 Upon successful completion, the nvlist will contain one nvpair for each of the
58 system attributes associated with \fIview\fR. The list of views and the
59 attributes associated with each view are listed below. Not all underlying file
60 systems support all views and all attributes. The nvlist will not contain an
61 nvpair for any attribute not supported by the underlying filesystem.
64 The \fBfsetattr()\fR function uses the nvlist pointed to by \fIrequest\fR to
65 update one or more of the system attribute's information about an open file
66 object specified by the file descriptor \fIfildes\fR, obtained from a
67 successful \fBopen()\fR, \fBcreat()\fR, \fBdup()\fR, \fBfcntl()\fR, or
68 \fBpipe()\fR function. The \fBsetattrat()\fR function first opens the extended
69 attribute file specified by \fIfilename\fR in the already opened file directory
70 object specified by \fIfildes\fR. It then uses the nvlist pointed to by
71 \fIrequest\fR to update one or more of the system attributes of filename.
74 If completion is not successful then no system attribute information is
78 The following chart lists the supported views, attributes, and data types for
86 View Attribute Data type
88 \fBXATTR_VIEW_READONLY\fR \fBA_FSID\fR \fBuint64_value\fR
89 \fBA_OPAQUE\fR \fBboolean_value\fR
90 \fBA_AV_SCANSTAMP\fR \fBuint8_array[]\fR
91 \fBXATTR_VIEW_READWRITE\fR \fBA_READONLY\fR \fBboolean_value\fR
92 \fBA_HIDDEN\fR \fBboolean_value\fR
93 \fBA_SYSTEM\fR \fBboolean_value\fR
94 \fBA_ARCHIVE\fR \fBboolean_value\fR
95 \fBA_CRTIME\fR \fBuint64_array\fR[2]
96 \fBA_NOUNLINK\fR \fBboolean_value\fR
97 \fBA_IMMUTABLE\fR \fBboolean_value\fR
98 \fBA_APPENDONLY\fR \fBboolean_value\fR
99 \fBA_NODUMP\fR \fBboolean_value\fR
100 \fBA_AV_QUARANTINED\fR \fBboolean_value\fR
101 \fBA_AV_MODIFIED\fR \fBboolean_value\fR
103 nvlist composed of \fBuint32_value\fR and \fBstring\fR
106 nvlist composed of \fBuint32_value\fR and \fBstring\fR
108 \fBA_OFFLINE\fR \fBboolean_value\fR
109 \fBA_SPARSE\fR \fBboolean_value\fR
114 Upon successful completion, 0 is returned. Otherwise, -1 is returned and
115 \fBerrno\fR is set to indicate the error.
118 The \fBfgetattr()\fR, \fBgetattrat()\fR, \fBfsetattr()\fR, and
119 \fBsetattrat()\fR, functions will fail if:
126 The \fIfildes\fR argument is not a valid open file descriptor.
135 The underlying file system does not support extended file attributes.
144 An error occurred while reading from the file system.
149 The \fBgetattrat()\fR and \fBsetattrat()\fR functions will fail if:
156 Search permission or write permission for \fIfilename\fR is denied.
165 The \fIfilename\fR argument does not name an existing file in the extended
166 attribute directory represented by \fIfildes\fR.
175 There are insufficient privileges to manipulate attributes.
180 \fBExample 1 \fRObtain an nvlist of readonly system attributes for an open file
184 Use \fBfgetattr()\fR to obtain an nvlist of the readonly system attributes for
185 the open file object represented by file descriptor \fIfildes\fR.
191 #include <sys/types.h>
193 #include <sys/nvpair.h>
196 nvpair_t *pair = NULL;
198 if (fgetattr(fildes, XATTR_VIEW_READONLY, &response)) {
201 while (pair = nvlist_next_nvpair(response, pair)) {
206 nvlist_free(response);
211 \fBExample 2 \fRSet the \fBA_READONLY\fR system attribute on an open file
215 Use \fBfsetattr()\fR to set the \fBA_OPAQUE\fR system attribute on the open
216 file object represented by file descriptor \fIfildes\fR.
222 nvpair_t *pair = NULL;
224 if (nvlist_alloc(&request, NV_UNIQUE_NAME, 0) != 0) {
227 if (nvlist_add_boolean_value(request, A_READONLY, 1) != 0) {
230 if (fsetattr(fildes, XATTR_VIEW_READWRITE, request)) {
237 \fBExample 3 \fRObtain an nvlist of the read/write system attributes for a
241 Use \fBgetattrat()\fR to obtain an nvlist of the read/write system attributes
242 for the file named \fBxattrfile\fR in the extended attribute directory of the
243 open file represented by file descriptor \fIfildes\fR.
249 nvpair_t *pair = NULL;
251 if (getattrat(fildes, XATTR_VIEW_READWRITE, "file", &response)) {
254 while (pair = nvlist_next_nvpair(response, pair)) {
259 nvlist_free(response);
264 \fBExample 4 \fRSet the \fBA_APPENDONLY\fR system attribute on a file.
267 Use \fBsetattrat()\fR to set the \fBA_APPENDONLY\fR system attribute on the
268 file named \fBfile\fR in the extended attribute directory of the open file
269 represented by file descriptor \fIfildes\fR.
275 nvpair_t *pair = NULL;
277 if (nvlist_alloc(&request, NV_UNIQUE_NAME, 0) != 0) {
280 if (nvlist_add_boolean_value(request, A_APPENDONLY, 1) != 0) {
283 if (setattrat(fildes, XATTR_VIEW_READWRITE, "file", request)) {
291 See \fBattributes\fR(5) for descriptions of the following attributes:
299 ATTRIBUTE TYPE ATTRIBUTE VALUE
301 Interface Stability Committed
308 \fBcreat\fR(2), \fBdup\fR(2), \fBfcntl\fR(2), \fBfstat\fR(2), \fBfstatat\fR(2),
309 \fBopen\fR(2), \fBpipe\fR(2), \fBlibnvpair\fR(3LIB), \fBattributes\fR(5),