1 .\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
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.
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.
24 .Nd set file system attributes
26 .Fd #include <sys/attr.h>
27 .Fd #include <unistd.h>
29 .Fn setattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
34 function sets attributes (that is, metadata) of file system objects.
35 It is the logical opposite of
37 The function sets attributes about the file system object specified by
39 from the values in the buffer specified by
45 parameter determines what attributes are set.
48 parameter lets you control specific aspects of the function's behaviour.
53 function is only supported by certain volume format implementations.
54 For maximum compatibility, client programs should use high-level APIs
55 (such as the Carbon File Manager) to access file system attributes.
56 These high-level APIs include logic to emulate file system attributes
57 on volumes that don't support
65 parameter must reference a valid file system object.
66 All directories listed in the path name leading to the object
68 You must own the file system object in order to set any of the
90 You must be root (that is, your process's effective UID must be 0) in order to change the
93 Setting other attributes requires that you have write access to the object.
96 .\" attrList parameter
100 parameter is a pointer to an
103 You are responsible for filling out all fields of this structure before calling the function.
104 See the discussion of the
106 function for a detailed description of this structure.
107 To set an attribute you must set the corresponding bit in the appropriate
114 .\" attrBuf and attrBufSize parameters
120 parameters specify a buffer that contains the attribute values to set.
121 Attributes are packed in exactly the same way as they are returned from
123 except that, when setting attributes, the buffer does not include the leading
132 parameter is a bit set that controls the behaviour of
134 The following option bits are defined.
136 .Bl -tag -width XXXbitmapcount
141 will not follow a symlink if it occurs as
142 the last component of
148 Upon successful completion a value of 0 is returned.
149 Otherwise, a value of -1 is returned and
151 is set to indicate the error.
154 Not all volumes support
156 However, if a volume supports
160 See the documentation for
162 for details on how to tell whether a volume supports it.
167 function has been undocumented for more than two years.
168 In that time a number of volume format implementations have been created without
169 a proper specification for the behaviour of this routine.
170 You may encounter volume format implementations with slightly different
171 behaviour than what is described here.
172 Your program is expected to be tolerant of this variant behaviour.
175 If you're implementing a volume format that supports
177 you should be careful to support the behaviour specified by this document.
185 The volume does not support
189 A component of the path prefix is not a directory.
191 .It Bq Er ENAMETOOLONG
192 A component of a path name exceeded
194 characters, or an entire path name exceeded
199 The file system object does not exist.
202 The volume is read-only.
205 Search permission is denied for a component of the path prefix.
208 Too many symbolic links were encountered in translating the pathname.
215 points to an invalid address.
223 .Dv ATTR_BIT_MAP_COUNT .
226 You try to set an invalid attribute.
229 You try to set an attribute that is read-only.
232 You try to set volume attributes and directory or file attributes at the same time.
235 You try to set volume attributes but
237 does not reference the root of the volume.
240 You try to set an attribute that can only be set by the owner.
243 You try to set an attribute that's only settable if you have write permission,
244 and you do not have write permission.
247 The buffer size you specified in
249 is too small to hold all the attributes that you are trying to set.
252 An I/O error occurred while reading from or writing to the file system.
258 If you try to set any volume attributes, you must set
262 field, even though it consumes no data from the attribute buffer.
265 For more caveats, see also the compatibility notes above.
269 The following code shows how to set the file type and creator of
270 a file by getting the
271 .Dv ATTR_CMN_FNDRINFO
274 modifying the appropriate fields of the 32-byte Finder information structure,
275 and then setting the attribute back using
277 This assumes that the target volume supports the required attributes
284 #include <sys/attr.h>
285 #include <sys/errno.h>
287 #include <sys/vnode.h>
290 typedef struct attrlist attrlist_t;
294 unsigned long length;
295 fsobj_type_t objType;
298 typedef struct FInfoAttrBuf FInfoAttrBuf;
301 static int FInfoDemo(
309 FInfoAttrBuf attrBuf;
312 assert( strlen(type) == 4 );
313 assert( strlen(creator) == 4 );
316 memset(&attrList, 0, sizeof(attrList));
317 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
318 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
321 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
327 if ( (err == 0) && (attrBuf.objType != VREG) ) {
328 fprintf(stderr, "Not a standard file.\en");
331 memcpy( &attrBuf.finderInfo[0], type, 4 );
332 memcpy( &attrBuf.finderInfo[4], creator, 4 );
334 attrList.commonattr = ATTR_CMN_FNDRINFO;
339 sizeof(attrBuf.finderInfo),
355 .Xr getdirentriesattr 2 ,
362 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).