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.
25 .Nd set file system attributes
27 .Fd #include <sys/attr.h>
28 .Fd #include <unistd.h>
30 .Fn setattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
32 .Fn fsetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
39 functions set attributes (that is, metadata) of file system objects.
40 They are the logical opposite of
44 function sets attributes about the file system object specified by
46 from the values in the buffer specified by
52 function does the same for the
57 parameter determines what attributes are set.
60 parameter lets you control specific aspects of the function's behaviour.
64 functions are only supported by certain volume format implementations.
65 For maximum compatibility, client programs should use high-level APIs
66 (such as the Carbon File Manager) to access file system attributes.
67 These high-level APIs include logic to emulate file system attributes
68 on volumes that don't support
80 must reference a valid file system object.
81 All directories listed in the path name leading to the object
87 must be a valid file descriptor for the calling process.
88 You must own the file system object in order to set any of the
110 You must be root (that is, your process's effective UID must be 0) in order to change the
113 Setting other attributes requires that you have write access to the object.
116 .\" attrList parameter
120 parameter is a pointer to an
123 You are responsible for filling out all fields of this structure before calling the function.
124 See the discussion of the
126 function for a detailed description of this structure.
127 To set an attribute you must set the corresponding bit in the appropriate
134 .\" attrBuf and attrBufSize parameters
140 parameters specify a buffer that contains the attribute values to set.
141 Attributes are packed in exactly the same way as they are returned from
143 except that, when setting attributes, the buffer does not include the leading
152 parameter is a bit set that controls the behaviour of
154 The following option bits are defined.
156 .Bl -tag -width XXXbitmapcount
161 will not follow a symlink if it occurs as
162 the last component of
168 Upon successful completion a value of 0 is returned.
169 Otherwise, a value of -1 is returned and
171 is set to indicate the error.
174 Not all volumes support
176 However, if a volume supports
180 See the documentation for
182 for details on how to tell whether a volume supports it.
187 function has been undocumented for more than two years.
188 In that time a number of volume format implementations have been created without
189 a proper specification for the behaviour of this routine.
190 You may encounter volume format implementations with slightly different
191 behaviour than what is described here.
192 Your program is expected to be tolerant of this variant behaviour.
195 If you're implementing a volume format that supports
197 you should be careful to support the behaviour specified by this document.
207 The call is not supported by the volume.
210 A component of the path for
212 prefix is not a directory.
214 .It Bq Er ENAMETOOLONG
215 A component of a path name for
219 characters, or an entire path name exceeded
224 The file system object for
229 The file descriptor argument for
231 is not a valid file descriptor.
234 The volume is read-only.
237 Search permission is denied for a component of the path prefix for
241 Too many symbolic links were encountered in translating the pathname for
249 points to an invalid address.
257 .Dv ATTR_BIT_MAP_COUNT .
260 You try to set an invalid attribute.
263 You try to set an attribute that is read-only.
266 You try to set volume attributes and directory or file attributes at the same time.
269 You try to set volume attributes but
271 does not reference the root of the volume.
274 You try to set an attribute that can only be set by the owner.
277 You try to set an attribute that's only settable if you have write permission,
278 and you do not have write permission.
281 The buffer size you specified in
283 is too small to hold all the attributes that you are trying to set.
286 An I/O error occurred while reading from or writing to the file system.
292 If you try to set any volume attributes, you must set
296 field, even though it consumes no data from the attribute buffer.
299 For more caveats, see also the compatibility notes above.
303 The following code shows how to set the file type and creator of
304 a file by getting the
305 .Dv ATTR_CMN_FNDRINFO
308 modifying the appropriate fields of the 32-byte Finder information structure,
309 and then setting the attribute back using
311 This assumes that the target volume supports the required attributes
318 #include <sys/attr.h>
319 #include <sys/errno.h>
321 #include <sys/vnode.h>
324 typedef struct attrlist attrlist_t;
327 struct FInfoAttrBuf {
329 fsobj_type_t objType;
332 typedef struct FInfoAttrBuf FInfoAttrBuf;
335 static int FInfoDemo(
343 FInfoAttrBuf attrBuf;
346 assert( strlen(type) == 4 );
347 assert( strlen(creator) == 4 );
350 memset(&attrList, 0, sizeof(attrList));
351 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
352 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
355 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
361 if ( (err == 0) && (attrBuf.objType != VREG) ) {
362 fprintf(stderr, "Not a standard file.\en");
365 memcpy( &attrBuf.finderInfo[0], type, 4 );
366 memcpy( &attrBuf.finderInfo[4], creator, 4 );
368 attrList.commonattr = ATTR_CMN_FNDRINFO;
373 sizeof(attrBuf.finderInfo),
389 .Xr getdirentriesattr 2 ,
396 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).