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