]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/setattrlist.2
xnu-1228.15.4.tar.gz
[apple/xnu.git] / bsd / man / man2 / setattrlist.2
... / ...
CommitLineData
1.\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
2.\"
3.\" The contents of this file constitute Original Code as defined in and
4.\" are subject to the Apple Public Source License Version 1.1 (the
5.\" "License"). You may not use this file except in compliance with the
6.\" License. Please obtain a copy of the License at
7.\" http://www.apple.com/publicsource and read it before using this file.
8.\"
9.\" This Original Code and all software distributed under the License are
10.\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
11.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
12.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
13.\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
14.\" License for the specific language governing rights and limitations
15.\" under the License.
16.\"
17.\" @(#)setattrlist.2
18.
19.Dd December 15, 2003
20.Dt SETATTRLIST 2
21.Os Darwin
22.Sh NAME
23.Nm setattrlist
24.Nd set file system attributes
25.Sh SYNOPSIS
26.Fd #include <sys/attr.h>
27.Fd #include <unistd.h>
28.Ft int
29.Fn setattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
30.
31.Sh DESCRIPTION
32The
33.Fn setattrlist
34function sets attributes (that is, metadata) of file system objects.
35It is the logical opposite of
36.Xr getattrlist 2 .
37The function sets attributes about the file system object specified by
38.Fa path
39from the values in the buffer specified by
40.Fa attrBuf
41and
42.Fa attrBufSize .
43The
44.Fa attrList
45parameter determines what attributes are set.
46The
47.Fa options
48parameter lets you control specific aspects of the function's behaviour.
49.Pp
50.
51The
52.Fn setattrlist
53function is only supported by certain volume format implementations.
54For maximum compatibility, client programs should use high-level APIs
55(such as the Carbon File Manager) to access file system attributes.
56These high-level APIs include logic to emulate file system attributes
57on volumes that don't support
58.Fn setattrlist .
59.Pp
60.
61.\" path parameter
62.
63The
64.Fa path
65parameter must reference a valid file system object.
66All directories listed in the path name leading to the object
67must be searchable.
68You must own the file system object in order to set any of the
69following attributes:
70.Pp
71.
72.Bl -item -compact
73.It
74ATTR_CMN_GRPID
75.It
76ATTR_CMN_ACCESSMASK
77.It
78ATTR_CMN_FLAGS
79.It
80ATTR_CMN_CRTIME
81.It
82ATTR_CMN_MODTIME
83.It
84ATTR_CMN_CHGTIME
85.It
86ATTR_CMN_ACCTIME
87.El
88.Pp
89.
90You must be root (that is, your process's effective UID must be 0) in order to change the
91.Dv ATTR_CMN_OWNERID
92attribute.
93Setting other attributes requires that you have write access to the object.
94.Pp
95.
96.\" attrList parameter
97.
98The
99.Fa attrList
100parameter is a pointer to an
101.Vt attrlist
102structure.
103You are responsible for filling out all fields of this structure before calling the function.
104See the discussion of the
105.Xr getattrlist 2
106function for a detailed description of this structure.
107To set an attribute you must set the corresponding bit in the appropriate
108.Vt attrgroup_t
109field of the
110.Vt attrlist
111structure.
112.Pp
113.
114.\" attrBuf and attrBufSize parameters
115.
116The
117.Fa attrBuf
118and
119.Fa attrBufSize
120parameters specify a buffer that contains the attribute values to set.
121Attributes are packed in exactly the same way as they are returned from
122.Xr getattrlist 2
123except that, when setting attributes, the buffer does not include the leading
124.Vt unsigned long
125length value.
126.Pp
127.
128.\" option parameter
129.
130The
131.Fa options
132parameter is a bit set that controls the behaviour of
133.Fn setattrlist .
134The following option bits are defined.
135.
136.Bl -tag -width XXXbitmapcount
137.
138.It FSOPT_NOFOLLOW
139If this bit is set,
140.Fn setattrlist
141will not follow a symlink if it occurs as
142the last component of
143.Fa path .
144.
145.El
146.
147.Sh RETURN VALUES
148Upon successful completion a value of 0 is returned.
149Otherwise, a value of -1 is returned and
150.Va errno
151is set to indicate the error.
152.
153.Sh COMPATIBILITY
154Not all volumes support
155.Fn setattrlist .
156However, if a volume supports
157.Xr getattrlist 2 ,
158it must also support
159.Fn setattrlist .
160See the documentation for
161.Xr getattrlist 2
162for details on how to tell whether a volume supports it.
163.Pp
164.
165The
166.Fn setattrlist
167function has been undocumented for more than two years.
168In that time a number of volume format implementations have been created without
169a proper specification for the behaviour of this routine.
170You may encounter volume format implementations with slightly different
171behaviour than what is described here.
172Your program is expected to be tolerant of this variant behaviour.
173.Pp
174.
175If you're implementing a volume format that supports
176.Fn setattrlist ,
177you should be careful to support the behaviour specified by this document.
178.
179.Sh ERRORS
180.Fn setattrlist
181will fail if:
182.Bl -tag -width Er
183.
184.It Bq Er ENOTSUP
185The volume does not support
186.Fn setattrlist .
187.
188.It Bq Er ENOTDIR
189A component of the path prefix is not a directory.
190.
191.It Bq Er ENAMETOOLONG
192A component of a path name exceeded
193.Dv NAME_MAX
194characters, or an entire path name exceeded
195.Dv PATH_MAX
196characters.
197.
198.It Bq Er ENOENT
199The file system object does not exist.
200.
201.It Bq Er EROFS
202The volume is read-only.
203.
204.It Bq Er EACCES
205Search permission is denied for a component of the path prefix.
206.
207.It Bq Er ELOOP
208Too many symbolic links were encountered in translating the pathname.
209.
210.It Bq Er EFAULT
211.Fa path ,
212.Fa attrList
213or
214.Em attrBuf
215points to an invalid address.
216.
217.It Bq Er EINVAL
218The
219.Fa bitmapcount
220field of
221.Fa attrList
222is not
223.Dv ATTR_BIT_MAP_COUNT .
224.
225.It Bq Er EINVAL
226You try to set an invalid attribute.
227.
228.It Bq Er EINVAL
229You try to set an attribute that is read-only.
230.
231.It Bq Er EINVAL
232You try to set volume attributes and directory or file attributes at the same time.
233.
234.It Bq Er EINVAL
235You try to set volume attributes but
236.Fa path
237does not reference the root of the volume.
238.
239.It Bq Er EPERM
240You try to set an attribute that can only be set by the owner.
241.
242.It Bq Er EACCES
243You try to set an attribute that's only settable if you have write permission,
244and you do not have write permission.
245.
246.It Bq Er EINVAL
247The buffer size you specified in
248.Fa attrBufSize
249is too small to hold all the attributes that you are trying to set.
250.
251.It Bq Er EIO
252An I/O error occurred while reading from or writing to the file system.
253.El
254.Pp
255.
256.Sh CAVEATS
257.
258If you try to set any volume attributes, you must set
259.Dv ATTR_VOL_INFO
260in the
261.Fa volattr
262field, even though it consumes no data from the attribute buffer.
263.Pp
264.
265For more caveats, see also the compatibility notes above.
266.
267.Sh EXAMPLES
268.
269The following code shows how to set the file type and creator of
270a file by getting the
271.Dv ATTR_CMN_FNDRINFO
272attribute using
273.Xr getattrlist 2 ,
274modifying the appropriate fields of the 32-byte Finder information structure,
275and then setting the attribute back using
276.Fn setattrlist .
277This assumes that the target volume supports the required attributes
278.
279.Bd -literal
280#include <assert.h>
281#include <stdio.h>
282#include <stddef.h>
283#include <string.h>
284#include <sys/attr.h>
285#include <sys/errno.h>
286#include <unistd.h>
287#include <sys/vnode.h>
288.Pp
289.
290typedef struct attrlist attrlist_t;
291.Pp
292.
293struct FInfoAttrBuf
294 unsigned long length;
295 fsobj_type_t objType;
296 char finderInfo[32];
297};
298typedef struct FInfoAttrBuf FInfoAttrBuf;
299.Pp
300.
301static int FInfoDemo(
302 const char *path,
303 const char *type,
304 const char *creator
305)
306{
307 int err;
308 attrlist_t attrList;
309 FInfoAttrBuf attrBuf;
310.Pp
311
312 assert( strlen(type) == 4 );
313 assert( strlen(creator) == 4 );
314.Pp
315.
316 memset(&attrList, 0, sizeof(attrList));
317 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
318 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
319.Pp
320
321 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
322 if (err != 0) {
323 err = errno;
324 }
325.Pp
326
327 if ( (err == 0) && (attrBuf.objType != VREG) ) {
328 fprintf(stderr, "Not a standard file.\en");
329 err = EINVAL;
330 } else {
331 memcpy( &attrBuf.finderInfo[0], type, 4 );
332 memcpy( &attrBuf.finderInfo[4], creator, 4 );
333
334 attrList.commonattr = ATTR_CMN_FNDRINFO;
335 err = setattrlist(
336 path,
337 &attrList,
338 attrBuf.finderInfo,
339 sizeof(attrBuf.finderInfo),
340 0
341 );
342 }
343.Pp
344 return err;
345}
346.Ed
347.Pp
348.
349.Sh SEE ALSO
350.
351.Xr chflags 2 ,
352.Xr chmod 2 ,
353.Xr chown 2 ,
354.Xr getattrlist 2 ,
355.Xr getdirentriesattr 2 ,
356.Xr searchfs 2 ,
357.Xr utimes 2
358.
359.Sh HISTORY
360A
361.Fn setattrlist
362function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
363.