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.
89 The list of potentially settable attributes via
91 is different than the list of attributes that are accessible via
93 In particular, only the following attributes are modifiable via
95 and not all of them may be supported on all filesystems.
122 ATTR_CMN_EXTENDED_SECURITY
137 You must own the file system object in order to set any of the
138 following attributes:
156 .Fa cannot be set programmatically. Any attempt to set change time is ignored.
160 You must be root (that is, your process's effective UID must be 0) in order to change the
163 Setting other attributes requires that you have write access to the object.
166 .\" attrList parameter
170 parameter is a pointer to an
173 You are responsible for filling out all fields of this structure before calling the function.
174 See the discussion of the
176 function for a detailed description of this structure.
177 To set an attribute you must set the corresponding bit in the appropriate
184 .\" attrBuf and attrBufSize parameters
190 parameters specify a buffer that contains the attribute values to set.
191 Attributes are packed in exactly the same way as they are returned from
193 except that, when setting attributes, the buffer does not include the leading
202 parameter is a bit set that controls the behaviour of
204 The following option bits are defined.
206 .Bl -tag -width XXXbitmapcount
211 will not follow a symlink if it occurs as
212 the last component of
218 Upon successful completion a value of 0 is returned.
219 Otherwise, a value of -1 is returned and
221 is set to indicate the error.
224 Not all volumes support
226 However, if a volume supports
230 See the documentation for
232 for details on how to tell whether a volume supports it.
237 function has been undocumented for more than two years.
238 In that time a number of volume format implementations have been created without
239 a proper specification for the behaviour of this routine.
240 You may encounter volume format implementations with slightly different
241 behaviour than what is described here.
242 Your program is expected to be tolerant of this variant behaviour.
245 If you're implementing a volume format that supports
247 you should be careful to support the behaviour specified by this document.
257 The call is not supported by the volume.
260 A component of the path for
262 prefix is not a directory.
264 .It Bq Er ENAMETOOLONG
265 A component of a path name for
269 characters, or an entire path name exceeded
274 The file system object for
279 The file descriptor argument for
281 is not a valid file descriptor.
284 The volume is read-only.
287 Search permission is denied for a component of the path prefix for
291 Too many symbolic links were encountered in translating the pathname for
299 points to an invalid address.
307 .Dv ATTR_BIT_MAP_COUNT .
310 You try to set an invalid attribute.
313 You try to set an attribute that is read-only.
316 You try to set volume attributes and directory or file attributes at the same time.
319 You try to set volume attributes but
321 does not reference the root of the volume.
324 You try to set an attribute that can only be set by the owner.
327 You try to set an attribute that's only settable if you have write permission,
328 and you do not have write permission.
331 The buffer size you specified in
333 is too small to hold all the attributes that you are trying to set.
336 An I/O error occurred while reading from or writing to the file system.
342 If you try to set any volume attributes, you must set
346 field, even though it consumes no data from the attribute buffer.
349 For more caveats, see also the compatibility notes above.
353 The following code shows how to set the file type and creator of
354 a file by getting the
355 .Dv ATTR_CMN_FNDRINFO
358 modifying the appropriate fields of the 32-byte Finder information structure,
359 and then setting the attribute back using
361 This assumes that the target volume supports the required attributes
368 #include <sys/attr.h>
369 #include <sys/errno.h>
371 #include <sys/vnode.h>
374 typedef struct attrlist attrlist_t;
377 struct FInfoAttrBuf {
379 fsobj_type_t objType;
382 typedef struct FInfoAttrBuf FInfoAttrBuf;
385 static int FInfoDemo(
393 FInfoAttrBuf attrBuf;
396 assert( strlen(type) == 4 );
397 assert( strlen(creator) == 4 );
400 memset(&attrList, 0, sizeof(attrList));
401 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
402 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
405 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
411 if ( (err == 0) && (attrBuf.objType != VREG) ) {
412 fprintf(stderr, "Not a standard file.\en");
415 memcpy( &attrBuf.finderInfo[0], type, 4 );
416 memcpy( &attrBuf.finderInfo[4], creator, 4 );
418 attrList.commonattr = ATTR_CMN_FNDRINFO;
423 sizeof(attrBuf.finderInfo),
439 .Xr getdirentriesattr 2 ,
446 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).