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.
17 .\" @(#)getdirentriesattr.2
20 .Dt GETDIRENTRIESATTR 2
24 .Nd get file system attributes for multiple directory entries
26 .Fd #include <sys/attr.h>
27 .Fd #include <unistd.h>
29 .Fn getdirentriesattr "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long * count" "unsigned long * basep" "unsigned long * newState" "unsigned long options"
35 function reads directory entries and returns their attributes (that is, metadata).
36 You can think of it as a combination of
40 The function reads directory entries from the directory referenced by the
43 Attributes of those directory entries are placed into the buffer specified by
49 parameter determines what attributes are returned for each entry.
52 parameter contains the number of directory entries requested and returned.
55 parameter returns the directory offset in a manner similar to
59 parameter allows you to check whether the directory has been modified while
63 parameter lets you control specific aspects of the function's behaviour.
68 function is only supported by certain volume format implementations.
69 For maximum compatibility, client programs should use high-level APIs
70 (such as the Carbon File Manager) to access file system attributes.
71 These high-level APIs include logic to emulate file system attributes
72 on volumes that don't support
73 .Fn getdirentriesattr .
80 parameter must be a file descriptor that references a directory that you have opened for reading.
83 .\" attrList parameter
87 parameter is a pointer to an
90 You are responsible for filling out all fields of this structure before calling the function.
91 See the discussion of the
93 function for a detailed description of this structure.
94 To get an attribute you must set the corresponding bit in the appropriate
99 You must not request volume attributes.
102 .\" attrBuf and attrBufSize parameters
108 parameters specify a buffer into which the function places attribute values.
109 The attributes for any given directory entry are grouped together and
110 packed in exactly the same way as they are returned from
112 These groups are then placed into the buffer, one after another.
113 As each group starts with a leading
116 overall length of the group, you can step from one group to the next
117 by simply adding this length to your pointer.
118 The sample code (below) shows how to do this.
119 The initial contents of this buffer are ignored.
126 parameter points to a
129 You should initialise this variable to be the number of directory entries for which
130 you wish to get attributes.
131 On return, this variable contains the number of directory entries whose attributes
132 have been placed into the attribute buffer.
133 This may be smaller than the number that you requested.
139 parameter returns the offset of the last directory entry read, in a
141 .Xr getdirentries 2 .
142 You can use this value to reset a directory iteration to a known position
145 The initial value of the variable is ignored.
148 .\" newState parameter
152 parameter returns a value that changes if the directory has been modified.
153 If you're iterating through the directory by making repeated calls to
154 .Fn getdirentriesattr ,
155 you can compare subsequent values of
157 to determine whether the directory has been modified (and thus restart
158 your iteration at the beginning).
159 The initial value of the variable is ignored.
162 .\" options parameter
166 parameter is a bit set that controls the behaviour of
167 .Fn getdirentriesattr .
168 The following option bits are defined.
170 .Bl -tag -width FSOPT_NOINMEMUPDATE
172 .It FSOPT_NOINMEMUPDATE
174 .Fn getdirentriesattr
175 to return the directory entries from disk rather than taking the extra step of looking
176 at data structures in-memory which may contain changes that haven't been flushed to disk.
178 This option allowed for specific performance optimizations for specific clients on older systems.
179 We currently recommend that clients not set this option and that file system
180 implementations ignore it.
184 It is typical to ask for a combination of common, file, and directory
185 attributes and then use the value of the
187 attribute to parse the resulting attribute buffer.
190 Upon successful completion a value of 0 or 1 is returned.
191 The value 0 indicates that the routine completed successfully.
192 The value 1 indicates that the routine completed successfully and has
193 returned the last entry in the directory.
194 On error, a value of -1 is returned and
196 is set to indicate the error.
199 Not all volumes support
200 .Fn getdirentriesattr .
201 You can test whether a volume supports
202 .Fn getdirentriesattr
205 to get the volume capabilities attribute
206 .Dv ATTR_VOL_CAPABILITIES ,
208 .Dv VOL_CAP_INT_READDIRATTR
213 .Fn getdirentriesattr
214 function has been undocumented for more than two years.
215 In that time a number of volume format implementations have been created without
216 a proper specification for the behaviour of this routine.
217 You may encounter volume format implementations with slightly different
218 behaviour than what is described here.
219 Your program is expected to be tolerant of this variant behaviour.
222 If you're implementing a volume format that supports
223 .Fn getdirentriesattr ,
224 you should be careful to support the behaviour specified by this document.
227 .Fn getdirentriesattr
232 The volume does not support
233 .Fn getdirentriesattr .
237 is not a valid file descriptor for a directory open for reading.
243 points to an invalid address.
251 .Dv ATTR_BIT_MAP_COUNT .
254 You requested an invalid attribute.
257 You requested volume attributes.
262 parameter contains an invalid flag.
265 An I/O error occurred while reading from or writing to the file system.
271 The following code lists the contents of a directory using
272 .Fn getdirentriesattr .
273 The listing includes the file type and creator for files.
280 #include <sys/attr.h>
281 #include <sys/errno.h>
283 #include <sys/vnode.h>
288 typedef struct attrlist attrlist_t;
291 struct FInfoAttrBuf {
292 unsigned long length;
293 attrreference_t name;
294 fsobj_type_t objType;
297 typedef struct FInfoAttrBuf FInfoAttrBuf;
305 static int FInfoDemo(const char *dirPath)
313 unsigned long junkBaseP;
315 unsigned long oldState;
316 unsigned long newState;
318 FInfoAttrBuf * thisEntry;
319 char attrBuf[kEntriesPerCall * (sizeof(FInfoAttrBuf) + 64)];
322 // attrBuf is big enough for kEntriesPerCall entries, assuming that
323 // the average name length is less than 64.
326 memset(&attrList, 0, sizeof(attrList));
327 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
328 attrList.commonattr = ATTR_CMN_NAME
334 dirFD = open(dirPath, O_RDONLY, 0);
339 oldStateValid = false;
342 count = kEntriesPerCall;
344 err = getdirentriesattr(
363 if (newState != oldState) {
364 printf("*** Directory has changed\en");
369 oldStateValid = true;
372 thisEntry = (FInfoAttrBuf *) attrBuf;
374 for (index = 0; index < count; index++) {
375 switch (thisEntry->objType) {
379 &thisEntry->finderInfo[0],
380 &thisEntry->finderInfo[4]
384 printf("directory ");
395 ((char *) &thisEntry->name)
396 + thisEntry->name.attr_dataoffset
399 // Advance to the next entry.
401 ((char *) thisEntry) += thisEntry->length;
404 } while ( err == 0 && ! done );
420 .Xr getdirentries 2 ,
425 .Fn getdirentriesattr
426 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).