xref: /freebsd/lib/libsys/extattr_get_file.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"
2*8269e767SBrooks Davis.\" Copyright (c) 2001 Dima Dorfman <dima@unixfreak.org>
3*8269e767SBrooks Davis.\" Copyright (c) 2003 Robert Watson <rwatson@FreeBSD.org>
4*8269e767SBrooks Davis.\" All rights reserved.
5*8269e767SBrooks Davis.\"
6*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
7*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
8*8269e767SBrooks Davis.\" are met:
9*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
12*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
13*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
14*8269e767SBrooks Davis.\"
15*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*8269e767SBrooks Davis.\" SUCH DAMAGE.
26*8269e767SBrooks Davis.\"
27*8269e767SBrooks Davis.Dd October 11, 2021
28*8269e767SBrooks Davis.Dt EXTATTR 2
29*8269e767SBrooks Davis.Os
30*8269e767SBrooks Davis.Sh NAME
31*8269e767SBrooks Davis.Nm extattr_delete_fd ,
32*8269e767SBrooks Davis.Nm extattr_delete_file ,
33*8269e767SBrooks Davis.Nm extattr_delete_link ,
34*8269e767SBrooks Davis.Nm extattr_get_fd ,
35*8269e767SBrooks Davis.Nm extattr_get_file ,
36*8269e767SBrooks Davis.Nm extattr_get_link ,
37*8269e767SBrooks Davis.Nm extattr_list_fd ,
38*8269e767SBrooks Davis.Nm extattr_list_file ,
39*8269e767SBrooks Davis.Nm extattr_list_link ,
40*8269e767SBrooks Davis.Nm extattr_set_fd ,
41*8269e767SBrooks Davis.Nm extattr_set_file ,
42*8269e767SBrooks Davis.Nm extattr_set_link
43*8269e767SBrooks Davis.Nd system calls to manipulate VFS extended attributes
44*8269e767SBrooks Davis.Sh LIBRARY
45*8269e767SBrooks Davis.Lb libc
46*8269e767SBrooks Davis.Sh SYNOPSIS
47*8269e767SBrooks Davis.In sys/types.h
48*8269e767SBrooks Davis.In sys/extattr.h
49*8269e767SBrooks Davis.Ft int
50*8269e767SBrooks Davis.Fn extattr_delete_fd "int fd" "int attrnamespace" "const char *attrname"
51*8269e767SBrooks Davis.Ft int
52*8269e767SBrooks Davis.Fn extattr_delete_file "const char *path" "int attrnamespace" "const char *attrname"
53*8269e767SBrooks Davis.Ft int
54*8269e767SBrooks Davis.Fn extattr_delete_link "const char *path" "int attrnamespace" "const char *attrname"
55*8269e767SBrooks Davis.Ft ssize_t
56*8269e767SBrooks Davis.Fn extattr_get_fd "int fd" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
57*8269e767SBrooks Davis.Ft ssize_t
58*8269e767SBrooks Davis.Fn extattr_get_file "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
59*8269e767SBrooks Davis.Ft ssize_t
60*8269e767SBrooks Davis.Fn extattr_get_link "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes"
61*8269e767SBrooks Davis.Ft ssize_t
62*8269e767SBrooks Davis.Fn extattr_list_fd "int fd" "int attrnamespace" "void *data" "size_t nbytes"
63*8269e767SBrooks Davis.Ft ssize_t
64*8269e767SBrooks Davis.Fn extattr_list_file "const char *path" "int attrnamespace" "void *data" "size_t nbytes"
65*8269e767SBrooks Davis.Ft ssize_t
66*8269e767SBrooks Davis.Fn extattr_list_link "const char *path" "int attrnamespace" "void *data" "size_t nbytes"
67*8269e767SBrooks Davis.Ft ssize_t
68*8269e767SBrooks Davis.Fn extattr_set_fd "int fd" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
69*8269e767SBrooks Davis.Ft ssize_t
70*8269e767SBrooks Davis.Fn extattr_set_file "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
71*8269e767SBrooks Davis.Ft ssize_t
72*8269e767SBrooks Davis.Fn extattr_set_link "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes"
73*8269e767SBrooks Davis.Sh DESCRIPTION
74*8269e767SBrooks DavisNamed extended attributes are meta-data associated with vnodes
75*8269e767SBrooks Davisrepresenting files and directories.
76*8269e767SBrooks DavisThey exist as
77*8269e767SBrooks Davis.Qq Li name=value
78*8269e767SBrooks Davispairs within a set of namespaces.
79*8269e767SBrooks Davis.Pp
80*8269e767SBrooks DavisThe
81*8269e767SBrooks Davis.Fn extattr_get_file
82*8269e767SBrooks Davissystem call retrieves the value of the specified extended attribute into
83*8269e767SBrooks Davisa buffer pointed to by
84*8269e767SBrooks Davis.Fa data
85*8269e767SBrooks Davisof size
86*8269e767SBrooks Davis.Fa nbytes .
87*8269e767SBrooks DavisThe
88*8269e767SBrooks Davis.Fn extattr_set_file
89*8269e767SBrooks Davissystem call sets the value of the specified extended attribute to the data
90*8269e767SBrooks Davisdescribed by
91*8269e767SBrooks Davis.Fa data .
92*8269e767SBrooks DavisThe
93*8269e767SBrooks Davis.Fn extattr_delete_file
94*8269e767SBrooks Davissystem call deletes the extended attribute specified.
95*8269e767SBrooks DavisThe
96*8269e767SBrooks Davis.Fn extattr_list_file
97*8269e767SBrooks Davisreturns a list of attributes present in the requested namespace.
98*8269e767SBrooks DavisEach list entry consists of a single byte containing the length
99*8269e767SBrooks Davisof the attribute name, followed by the attribute name.
100*8269e767SBrooks DavisThe attribute name is not terminated by ASCII 0 (nul).
101*8269e767SBrooks DavisThe
102*8269e767SBrooks Davis.Fn extattr_get_file
103*8269e767SBrooks Davisand
104*8269e767SBrooks Davis.Fn extattr_list_file
105*8269e767SBrooks Daviscalls consume the
106*8269e767SBrooks Davis.Fa data
107*8269e767SBrooks Davisand
108*8269e767SBrooks Davis.Fa nbytes
109*8269e767SBrooks Davisarguments in the style of
110*8269e767SBrooks Davis.Xr read 2 ;
111*8269e767SBrooks Davis.Fn extattr_set_file
112*8269e767SBrooks Davisconsumes these arguments in the style of
113*8269e767SBrooks Davis.Xr write 2 .
114*8269e767SBrooks Davis.Pp
115*8269e767SBrooks DavisIf
116*8269e767SBrooks Davis.Fa data
117*8269e767SBrooks Davisis
118*8269e767SBrooks Davis.Dv NULL
119*8269e767SBrooks Davisin a call to
120*8269e767SBrooks Davis.Fn extattr_get_file
121*8269e767SBrooks Davisand
122*8269e767SBrooks Davis.Fn extattr_list_file
123*8269e767SBrooks Davisthen the size of defined extended attribute data will be returned, rather
124*8269e767SBrooks Davisthan the quantity read, permitting applications to test the size of the
125*8269e767SBrooks Davisdata without performing a read.
126*8269e767SBrooks DavisThe
127*8269e767SBrooks Davis.Fn extattr_delete_link ,
128*8269e767SBrooks Davis.Fn extattr_get_link ,
129*8269e767SBrooks Davisand
130*8269e767SBrooks Davis.Fn extattr_set_link
131*8269e767SBrooks Davissystem calls behave in the same way as their _file counterparts, except that
132*8269e767SBrooks Davisthey do not follow symlinks.
133*8269e767SBrooks Davis.Pp
134*8269e767SBrooks DavisThe
135*8269e767SBrooks Davis.Fn extattr_get_fd ,
136*8269e767SBrooks Davis.Fn extattr_delete_fd ,
137*8269e767SBrooks Davis.Fn extattr_list_fd ,
138*8269e767SBrooks Davisand
139*8269e767SBrooks Davis.Fn extattr_set_fd
140*8269e767SBrooks Daviscalls are identical to their
141*8269e767SBrooks Davis.Qq Li _file
142*8269e767SBrooks Daviscounterparts except for the first argument.
143*8269e767SBrooks DavisThe
144*8269e767SBrooks Davis.Qq Li _fd
145*8269e767SBrooks Davisfunctions take a file descriptor, while the
146*8269e767SBrooks Davis.Qq Li _file
147*8269e767SBrooks Davisfunctions take a path.
148*8269e767SBrooks DavisBoth arguments describe a file associated with the extended attribute
149*8269e767SBrooks Davisthat should be manipulated.
150*8269e767SBrooks DavisThe
151*8269e767SBrooks Davis.Qq Li _fd
152*8269e767SBrooks Davisfunctions can be used with file descriptors opened with the
153*8269e767SBrooks Davis.Dv O_PATH
154*8269e767SBrooks Davisflag.
155*8269e767SBrooks Davis.Pp
156*8269e767SBrooks DavisThe following arguments are common to all the system calls described here:
157*8269e767SBrooks Davis.Bl -tag -width attrnamespace
158*8269e767SBrooks Davis.It Fa attrnamespace
159*8269e767SBrooks Davisthe namespace in which the extended attribute resides; see
160*8269e767SBrooks Davis.Xr extattr 9
161*8269e767SBrooks Davis.It Fa attrname
162*8269e767SBrooks Davisthe name of the extended attribute
163*8269e767SBrooks Davis.El
164*8269e767SBrooks Davis.Pp
165*8269e767SBrooks DavisNamed extended attribute semantics vary by file system implementing the call.
166*8269e767SBrooks DavisNot all operations may be supported for a particular attribute.
167*8269e767SBrooks DavisAdditionally, the format of the data in
168*8269e767SBrooks Davis.Fa data
169*8269e767SBrooks Davisis attribute-specific.
170*8269e767SBrooks Davis.Pp
171*8269e767SBrooks DavisFor more information on named extended attributes, please see
172*8269e767SBrooks Davis.Xr extattr 9 .
173*8269e767SBrooks Davis.Sh RETURN VALUES
174*8269e767SBrooks DavisIf successful, the
175*8269e767SBrooks Davis.Fn extattr_get_fd ,
176*8269e767SBrooks Davis.Fn extattr_get_file ,
177*8269e767SBrooks Davis.Fn extattr_get_link ,
178*8269e767SBrooks Davis.Fn extattr_list_fd ,
179*8269e767SBrooks Davis.Fn extattr_list_file ,
180*8269e767SBrooks Davis.Fn extattr_list_link ,
181*8269e767SBrooks Davis.Fn extattr_set_fd ,
182*8269e767SBrooks Davis.Fn extattr_set_file ,
183*8269e767SBrooks Davisand
184*8269e767SBrooks Davis.Fn extattr_set_link
185*8269e767SBrooks Daviscalls return the number of bytes
186*8269e767SBrooks Davisthat were read or written from the
187*8269e767SBrooks Davis.Fa data ,
188*8269e767SBrooks Davisrespectively.
189*8269e767SBrooks DavisIf
190*8269e767SBrooks Davis.Fa data
191*8269e767SBrooks Daviswas
192*8269e767SBrooks Davis.Dv NULL ,
193*8269e767SBrooks Davisthen
194*8269e767SBrooks Davis.Fn extattr_get_fd ,
195*8269e767SBrooks Davis.Fn extattr_get_file ,
196*8269e767SBrooks Davis.Fn extattr_get_link ,
197*8269e767SBrooks Davis.Fn extattr_list_fd ,
198*8269e767SBrooks Davis.Fn extattr_list_file ,
199*8269e767SBrooks Davisand
200*8269e767SBrooks Davis.Fn extattr_list_link
201*8269e767SBrooks Davisreturn the number of bytes available to read.
202*8269e767SBrooks DavisIf any of the calls are unsuccessful, the value \-1 is returned
203*8269e767SBrooks Davisand the global variable
204*8269e767SBrooks Davis.Va errno
205*8269e767SBrooks Davisis set to indicate the error.
206*8269e767SBrooks Davis.Pp
207*8269e767SBrooks Davis.Rv -std extattr_delete_file
208*8269e767SBrooks Davis.Sh ERRORS
209*8269e767SBrooks DavisThe following errors may be returned by the system calls themselves.
210*8269e767SBrooks DavisAdditionally, the file system implementing the call may return any
211*8269e767SBrooks Davisother errors it desires.
212*8269e767SBrooks Davis.Bl -tag -width Er
213*8269e767SBrooks Davis.It Bq Er EFAULT
214*8269e767SBrooks DavisThe
215*8269e767SBrooks Davis.Fa attrnamespace
216*8269e767SBrooks Davisand
217*8269e767SBrooks Davis.Fa attrname
218*8269e767SBrooks Davisarguments,
219*8269e767SBrooks Davisor the memory range defined by
220*8269e767SBrooks Davis.Fa data
221*8269e767SBrooks Davisand
222*8269e767SBrooks Davis.Fa nbytes
223*8269e767SBrooks Davispoint outside the process's allocated address space.
224*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
225*8269e767SBrooks DavisThe attribute name was longer than
226*8269e767SBrooks Davis.Dv EXTATTR_MAXNAMELEN .
227*8269e767SBrooks Davis.El
228*8269e767SBrooks Davis.Pp
229*8269e767SBrooks DavisThe
230*8269e767SBrooks Davis.Fn extattr_get_fd ,
231*8269e767SBrooks Davis.Fn extattr_set_fd ,
232*8269e767SBrooks Davis.Fn extattr_delete_fd ,
233*8269e767SBrooks Davisand
234*8269e767SBrooks Davis.Fn extattr_list_fd
235*8269e767SBrooks Davissystem calls may also fail if:
236*8269e767SBrooks Davis.Bl -tag -width Er
237*8269e767SBrooks Davis.It Bq Er EBADF
238*8269e767SBrooks DavisThe file descriptor referenced by
239*8269e767SBrooks Davis.Fa fd
240*8269e767SBrooks Daviswas invalid.
241*8269e767SBrooks Davis.El
242*8269e767SBrooks Davis.Pp
243*8269e767SBrooks DavisAdditionally, the
244*8269e767SBrooks Davis.Fn extattr_get_file ,
245*8269e767SBrooks Davis.Fn extattr_set_file ,
246*8269e767SBrooks Davisand
247*8269e767SBrooks Davis.Fn extattr_delete_file
248*8269e767SBrooks Daviscalls may also fail due to the following errors:
249*8269e767SBrooks Davis.Bl -tag -width Er
250*8269e767SBrooks Davis.It Bq Er ENOATTR
251*8269e767SBrooks DavisThe requested attribute was not defined for this file.
252*8269e767SBrooks Davis.It Bq Er ENOTDIR
253*8269e767SBrooks DavisA component of the path prefix is not a directory.
254*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
255*8269e767SBrooks DavisA component of a pathname exceeded 255 characters,
256*8269e767SBrooks Davisor an entire path name exceeded 1023 characters.
257*8269e767SBrooks Davis.It Bq Er ENOENT
258*8269e767SBrooks DavisA component of the path name that must exist does not exist.
259*8269e767SBrooks Davis.It Bq Er EACCES
260*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix.
261*8269e767SBrooks Davis.\" XXX are any missing?
262*8269e767SBrooks Davis.El
263*8269e767SBrooks Davis.Sh SEE ALSO
264*8269e767SBrooks Davis.Xr extattr 3 ,
265*8269e767SBrooks Davis.Xr getextattr 8 ,
266*8269e767SBrooks Davis.Xr setextattr 8 ,
267*8269e767SBrooks Davis.Xr extattr 9 ,
268*8269e767SBrooks Davis.Xr VOP_GETEXTATTR 9 ,
269*8269e767SBrooks Davis.Xr VOP_SETEXTATTR 9
270*8269e767SBrooks Davis.Sh HISTORY
271*8269e767SBrooks DavisExtended attribute support was developed as part of the
272*8269e767SBrooks Davis.Tn TrustedBSD
273*8269e767SBrooks DavisProject, and introduced in
274*8269e767SBrooks Davis.Fx 5.0 .
275*8269e767SBrooks DavisIt was developed to support security extensions requiring additional labels
276*8269e767SBrooks Davisto be associated with each file or directory.
277*8269e767SBrooks Davis.Sh CAVEATS
278*8269e767SBrooks DavisThis interface is under active development, and as such is subject to
279*8269e767SBrooks Davischange as applications are adapted to use it.
280*8269e767SBrooks DavisDevelopers are discouraged from relying on its stability.
281*8269e767SBrooks Davis.Sh BUGS
282*8269e767SBrooks DavisIn earlier versions of this API, passing an empty string for the
283*8269e767SBrooks Davisattribute name to
284*8269e767SBrooks Davis.Fn extattr_get_fd ,
285*8269e767SBrooks Davis.Fn extattr_get_file ,
286*8269e767SBrooks Davisor
287*8269e767SBrooks Davis.Fn extattr_get_link
288*8269e767SBrooks Daviswould return the list of attributes defined for the target object.
289*8269e767SBrooks DavisThis interface has been deprecated in preference to using the explicit
290*8269e767SBrooks Davislist API, and should not be used.
291