1 q.\" 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
23 .Nm getdirentriesattr(NOW DEPRECATED)
24 .Nd get file system attributes for multiple directory entries
26 .Fd #include <sys/attr.h>
27 .Fd #include <unistd.h>
31 .Fn getdirentriesattr "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned int * count" "unsigned int * basep" "unsigned int * newState" "unsigned int options"
34 .Fn getdirentriesattr "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long * count" "unsigned long * basep" "unsigned long * newState" "unsigned long options"
41 function reads directory entries and returns their attributes (that is, metadata).
42 You can think of it as a combination of
47 iterates over the items in a directory like
49 and returns information about each directory entry like
53 returns information about a symbolic link, the information returned is about the link itself, not the target of the link.
55 The function reads directory entries from the directory referenced by the
58 Attributes of those directory entries are placed into the buffer specified by
64 parameter determines what attributes are returned for each entry.
67 parameter contains the number of directory entries requested and returned.
70 parameter returns the directory offset in a manner similar to
74 parameter allows you to check whether the directory has been modified while
78 parameter lets you control specific aspects of the function's behaviour.
83 function is only supported by certain volume format implementations.
84 For maximum compatibility, client programs should use high-level APIs
85 (such as the Carbon File Manager) to access file system attributes.
86 These high-level APIs include logic to emulate file system attributes
87 on volumes that don't support
88 .Fn getdirentriesattr .
95 parameter must be a file descriptor that references a directory that you have opened for reading.
98 .\" attrList parameter
102 parameter is a pointer to an
105 You are responsible for filling out all fields of this structure before calling the function.
106 See the discussion of the
108 function for a detailed description of this structure.
109 To get an attribute you must set the corresponding bit in the appropriate
114 You must not request volume attributes.
117 .\" attrBuf and attrBufSize parameters
123 parameters specify a buffer into which the function places attribute values.
124 The attributes for any given directory entry are grouped together and
125 packed in exactly the same way as they are returned from
127 These groups are then placed into the buffer, one after another.
128 As each group starts with a leading
131 overall length of the group, you can step from one group to the next
132 by simply adding this length to your pointer.
133 The sample code (below) shows how to do this.
134 The initial contents of this buffer are ignored.
141 parameter points to an
146 You should initialise this variable to be the number of directory entries for which
147 you wish to get attributes.
148 On return, this variable contains the number of directory entries whose attributes
149 have been placed into the attribute buffer.
150 This may be smaller than the number that you requested.
156 parameter returns the offset of the last directory entry read, in a
158 .Xr getdirentries 2 .
159 You can use this value to reset a directory iteration to a known position
162 However, since the variable is too small to hold an
166 to get the directory's current position instead of using this parameter.
167 The initial value of the variable is ignored.
170 .\" newState parameter
174 parameter returns a value that changes if the directory has been modified.
175 If you're iterating through the directory by making repeated calls to
176 .Fn getdirentriesattr ,
177 you can compare subsequent values of
179 to determine whether the directory has been modified (and thus restart
180 your iteration at the beginning).
181 The initial value of the variable is ignored.
184 .\" options parameter
188 parameter is a bit set that controls the behaviour of
189 .Fn getdirentriesattr .
190 The following option bits are defined.
192 .Bl -tag -width FSOPT_NOINMEMUPDATE
194 .It FSOPT_NOINMEMUPDATE
196 .Fn getdirentriesattr
197 to return the directory entries from disk rather than taking the extra step of looking
198 at data structures in-memory which may contain changes that haven't been flushed to disk.
200 This option allowed for specific performance optimizations for specific clients on older systems.
201 We currently recommend that clients not set this option and that file system
202 implementations ignore it.
206 It is typical to ask for a combination of common, file, and directory
207 attributes and then use the value of the
209 attribute to parse the resulting attribute buffer.
211 As of Mac OS X 10.10,
212 .Fn getdirentriesattr
213 is deprecated. It is replaced by
214 .Nm getattrlistbulk(2).
216 .Fn getdirentriesattr
217 is strongly discouraged as comprehensive results are not guaranteed.
219 Upon successful completion a value of 0 or 1 is returned.
220 The value 0 indicates that the routine completed successfully.
221 The value 1 indicates that the routine completed successfully and has
222 returned the last entry in the directory.
223 On error, a value of -1 is returned and
225 is set to indicate the error.
228 Not all volumes support
229 .Fn getdirentriesattr .
230 You can test whether a volume supports
231 .Fn getdirentriesattr
234 to get the volume capabilities attribute
235 .Dv ATTR_VOL_CAPABILITIES ,
237 .Dv VOL_CAP_INT_READDIRATTR
242 .Fn getdirentriesattr
243 function has been undocumented for more than two years.
244 In that time a number of volume format implementations have been created without
245 a proper specification for the behaviour of this routine.
246 You may encounter volume format implementations with slightly different
247 behaviour than what is described here.
248 Your program is expected to be tolerant of this variant behaviour.
251 If you're implementing a volume format that supports
252 .Fn getdirentriesattr ,
253 you should be careful to support the behaviour specified by this document.
256 If the directory contains a mount point, then
257 .Dq DIR_MNTSTATUS_MNTPOINT
259 .Dv ATTR_DIR_MOUNTSTATUS
260 for that entry; all other attributes for that entry, however,
261 will be for the underlying file system (as opposed to the mounted
264 should be used to get the attributes for the mount point.
266 A directory which is a firmlink will have the
269 ATTR_CMN_FLAGS attribute entry.
270 However the attributes returned by
271 .Fn getdirentriesattr
272 will be those from the firmlink, not the firmlink's target.
273 To get the attributes of the firmlink's target, call
277 .Fn getdirentriesattr
282 The volume does not support
283 .Fn getdirentriesattr .
287 is not a valid file descriptor for a directory open for reading.
293 points to an invalid address.
301 .Dv ATTR_BIT_MAP_COUNT .
304 You requested an invalid attribute.
307 You requested volume attributes.
312 parameter contains an invalid flag.
315 An I/O error occurred while reading from or writing to the file system.
321 The following code lists the contents of a directory using
322 .Fn getdirentriesattr .
323 The listing includes the file type and creator for files.
330 #include <sys/attr.h>
331 #include <sys/errno.h>
333 #include <sys/vnode.h>
338 typedef struct attrlist attrlist_t;
341 struct FInfoAttrBuf {
343 attrreference_t name;
344 fsobj_type_t objType;
347 } __attribute__((aligned(4), packed));
348 typedef struct FInfoAttrBuf FInfoAttrBuf;
356 static int FInfoDemo(const char *dirPath)
365 unsigned int junkBaseP;
366 unsigned int oldState;
367 unsigned int newState;
371 unsigned long junkBaseP;
372 unsigned long oldState;
373 unsigned long newState;
377 FInfoAttrBuf * thisEntry;
378 char attrBuf[kEntriesPerCall * (sizeof(FInfoAttrBuf) + 64)];
381 // attrBuf is big enough for kEntriesPerCall entries, assuming that
382 // the average name length is less than 64.
385 memset(&attrList, 0, sizeof(attrList));
386 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
387 attrList.commonattr = ATTR_CMN_NAME
390 attrList.dirattr = ATTR_DIR_MOUNTSTATUS;
394 dirFD = open(dirPath, O_RDONLY, 0);
399 oldStateValid = false;
402 count = kEntriesPerCall;
404 err = getdirentriesattr(
423 if (newState != oldState) {
424 printf("*** Directory has changed\en");
429 oldStateValid = true;
432 thisEntry = (FInfoAttrBuf *) attrBuf;
434 for (index = 0; index < count; index++) {
435 switch (thisEntry->objType) {
439 &thisEntry->finderInfo[0],
440 &thisEntry->finderInfo[4]
444 if (thisEntry->dirStatus & DIR_MNTSTATUS_MNTPOINT)
445 printf("mount-point ");
447 printf("directory ");
458 ((char *) &thisEntry->name)
459 + thisEntry->name.attr_dataoffset
462 // Advance to the next entry.
464 thisEntry = (FInfoAttrBuf*)((char*)thisEntry + thisEntry->length);
467 } while ( err == 0 && ! done );
483 .Xr getdirentries 2 ,
488 .Fn getdirentriesattr
489 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).