]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/setattrlist.2
xnu-3248.20.55.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.
3e170ce0
A
88.
89The list of potentially settable attributes via
90.Fn setattrlist
91is different than the list of attributes that are accessible via
92.Fn getattrlist
93In particular, only the following attributes are modifiable via
94.Fn setattrlist
95and not all of them may be supported on all filesystems.
96.Pp
97.
98.Bl -item -compact
99.It
100ATTR_CMN_SCRIPT
101.It
102ATTR_CMN_CRTIME
103.It
104ATTR_CMN_MODTIME
105.It
106ATTR_CMN_CHGTIME
107.It
108ATTR_CMN_ACCTIME
109.It
110ATTR_CMN_BKUPTIME
111.It
112ATTR_CMN_FNDRINFO
113.It
114ATTR_CMN_OWNERID
115.It
116ATTR_CMN_GRPID
117.It
118ATTR_CMN_ACCESSMASK
119.It
120ATTR_CMN_FLAGS
121.It
122ATTR_CMN_EXTENDED_SECURITY
123.It
124ATTR_CMN_GRPUUID
125.Pp
126.It
127ATTR_VOL_NAME
128.It
129ATTR_VOL_INFO
130.Pp
131.It
132ATTR_FILE_DEVTYPE
133.El
134.Pp
135.
136.
91447636
A
137You must own the file system object in order to set any of the
138following attributes:
139.Pp
140.
141.Bl -item -compact
142.It
143ATTR_CMN_GRPID
144.It
145ATTR_CMN_ACCESSMASK
146.It
147ATTR_CMN_FLAGS
148.It
149ATTR_CMN_CRTIME
150.It
151ATTR_CMN_MODTIME
152.It
91447636 153ATTR_CMN_ACCTIME
3e170ce0
A
154.Pp
155ATTR_CMN_CHGTIME
156.Fa cannot be set programmatically. Any attempt to set change time is ignored.
91447636
A
157.El
158.Pp
159.
160You must be root (that is, your process's effective UID must be 0) in order to change the
161.Dv ATTR_CMN_OWNERID
3e170ce0 162attribute
91447636
A
163Setting other attributes requires that you have write access to the object.
164.Pp
165.
166.\" attrList parameter
167.
168The
169.Fa attrList
170parameter is a pointer to an
171.Vt attrlist
172structure.
173You are responsible for filling out all fields of this structure before calling the function.
174See the discussion of the
175.Xr getattrlist 2
176function for a detailed description of this structure.
177To set an attribute you must set the corresponding bit in the appropriate
178.Vt attrgroup_t
179field of the
180.Vt attrlist
181structure.
182.Pp
183.
184.\" attrBuf and attrBufSize parameters
185.
186The
187.Fa attrBuf
188and
189.Fa attrBufSize
190parameters specify a buffer that contains the attribute values to set.
191Attributes are packed in exactly the same way as they are returned from
192.Xr getattrlist 2
193except that, when setting attributes, the buffer does not include the leading
b0d623f7 194.Vt u_int32_t
91447636
A
195length value.
196.Pp
197.
198.\" option parameter
199.
200The
201.Fa options
202parameter is a bit set that controls the behaviour of
203.Fn setattrlist .
204The following option bits are defined.
205.
206.Bl -tag -width XXXbitmapcount
207.
208.It FSOPT_NOFOLLOW
209If this bit is set,
210.Fn setattrlist
211will not follow a symlink if it occurs as
212the last component of
213.Fa path .
214.
215.El
216.
217.Sh RETURN VALUES
218Upon successful completion a value of 0 is returned.
219Otherwise, a value of -1 is returned and
220.Va errno
221is set to indicate the error.
222.
223.Sh COMPATIBILITY
224Not all volumes support
225.Fn setattrlist .
226However, if a volume supports
227.Xr getattrlist 2 ,
228it must also support
229.Fn setattrlist .
230See the documentation for
231.Xr getattrlist 2
232for details on how to tell whether a volume supports it.
233.Pp
234.
235The
236.Fn setattrlist
237function has been undocumented for more than two years.
238In that time a number of volume format implementations have been created without
239a proper specification for the behaviour of this routine.
240You may encounter volume format implementations with slightly different
241behaviour than what is described here.
242Your program is expected to be tolerant of this variant behaviour.
243.Pp
244.
245If you're implementing a volume format that supports
246.Fn setattrlist ,
247you should be careful to support the behaviour specified by this document.
248.
249.Sh ERRORS
250.Fn setattrlist
b0d623f7
A
251and
252.Fn fsetattrlist
91447636
A
253will fail if:
254.Bl -tag -width Er
255.
256.It Bq Er ENOTSUP
b0d623f7 257The call is not supported by the volume.
91447636
A
258.
259.It Bq Er ENOTDIR
b0d623f7
A
260A component of the path for
261.Fn setattrlist
262prefix is not a directory.
91447636
A
263.
264.It Bq Er ENAMETOOLONG
b0d623f7
A
265A component of a path name for
266.Fn setattrlist
267exceeded
91447636
A
268.Dv NAME_MAX
269characters, or an entire path name exceeded
270.Dv PATH_MAX
271characters.
272.
273.It Bq Er ENOENT
b0d623f7
A
274The file system object for
275.Fn setattrlist
276does not exist.
277.
278.It Bq Er EBADF
279The file descriptor argument for
280.Fn fsetattrlist
281is not a valid file descriptor.
91447636
A
282.
283.It Bq Er EROFS
284The volume is read-only.
285.
286.It Bq Er EACCES
b0d623f7
A
287Search permission is denied for a component of the path prefix for
288.Fn setattrlist .
91447636
A
289.
290.It Bq Er ELOOP
b0d623f7
A
291Too many symbolic links were encountered in translating the pathname for
292.Fn setattrlist .
91447636
A
293.
294.It Bq Er EFAULT
295.Fa path ,
296.Fa attrList
297or
298.Em attrBuf
299points to an invalid address.
300.
301.It Bq Er EINVAL
302The
303.Fa bitmapcount
304field of
305.Fa attrList
306is not
307.Dv ATTR_BIT_MAP_COUNT .
308.
309.It Bq Er EINVAL
310You try to set an invalid attribute.
311.
312.It Bq Er EINVAL
313You try to set an attribute that is read-only.
314.
315.It Bq Er EINVAL
316You try to set volume attributes and directory or file attributes at the same time.
317.
318.It Bq Er EINVAL
319You try to set volume attributes but
320.Fa path
321does not reference the root of the volume.
322.
323.It Bq Er EPERM
324You try to set an attribute that can only be set by the owner.
325.
326.It Bq Er EACCES
327You try to set an attribute that's only settable if you have write permission,
328and you do not have write permission.
329.
330.It Bq Er EINVAL
331The buffer size you specified in
332.Fa attrBufSize
333is too small to hold all the attributes that you are trying to set.
334.
335.It Bq Er EIO
336An I/O error occurred while reading from or writing to the file system.
337.El
338.Pp
339.
340.Sh CAVEATS
341.
342If you try to set any volume attributes, you must set
343.Dv ATTR_VOL_INFO
344in the
345.Fa volattr
346field, even though it consumes no data from the attribute buffer.
347.Pp
348.
349For more caveats, see also the compatibility notes above.
350.
351.Sh EXAMPLES
352.
353The following code shows how to set the file type and creator of
354a file by getting the
355.Dv ATTR_CMN_FNDRINFO
356attribute using
357.Xr getattrlist 2 ,
358modifying the appropriate fields of the 32-byte Finder information structure,
359and then setting the attribute back using
360.Fn setattrlist .
361This assumes that the target volume supports the required attributes
362.
363.Bd -literal
364#include <assert.h>
365#include <stdio.h>
366#include <stddef.h>
367#include <string.h>
368#include <sys/attr.h>
369#include <sys/errno.h>
370#include <unistd.h>
371#include <sys/vnode.h>
372.Pp
373.
374typedef struct attrlist attrlist_t;
375.Pp
376.
b0d623f7
A
377struct FInfoAttrBuf {
378 u_int32_t length;
91447636
A
379 fsobj_type_t objType;
380 char finderInfo[32];
381};
382typedef struct FInfoAttrBuf FInfoAttrBuf;
383.Pp
384.
385static int FInfoDemo(
386 const char *path,
387 const char *type,
388 const char *creator
389)
390{
391 int err;
392 attrlist_t attrList;
393 FInfoAttrBuf attrBuf;
394.Pp
395
396 assert( strlen(type) == 4 );
397 assert( strlen(creator) == 4 );
398.Pp
399.
400 memset(&attrList, 0, sizeof(attrList));
401 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
402 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
403.Pp
404
405 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
406 if (err != 0) {
407 err = errno;
408 }
409.Pp
410
411 if ( (err == 0) && (attrBuf.objType != VREG) ) {
412 fprintf(stderr, "Not a standard file.\en");
413 err = EINVAL;
414 } else {
415 memcpy( &attrBuf.finderInfo[0], type, 4 );
416 memcpy( &attrBuf.finderInfo[4], creator, 4 );
417
418 attrList.commonattr = ATTR_CMN_FNDRINFO;
419 err = setattrlist(
420 path,
421 &attrList,
422 attrBuf.finderInfo,
423 sizeof(attrBuf.finderInfo),
424 0
425 );
426 }
427.Pp
428 return err;
429}
430.Ed
431.Pp
432.
433.Sh SEE ALSO
434.
435.Xr chflags 2 ,
436.Xr chmod 2 ,
437.Xr chown 2 ,
438.Xr getattrlist 2 ,
439.Xr getdirentriesattr 2 ,
440.Xr searchfs 2 ,
441.Xr utimes 2
442.
443.Sh HISTORY
444A
445.Fn setattrlist
446function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
447.