date and time created 89/06/06 23:01:32 by mckusick
[unix-history] / usr / src / lib / libc / sys / getdirentries.2
CommitLineData
0b0a22c4
KM
1.\" Copyright (c) 1989 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)getdirentries.2 6.1 (Berkeley) %G%
17.\"
18.TH GETDIRENTRIES 2 ""
19.UC 7
20.SH NAME
21getdirentries \- get directory entries in a filesystem independent format
22.SH SYNOPSIS
23.nf
24.ft B
25#include <sys/dirent.h>
26.LP
27.ft B
28cc = getdirentries(fd, buf, nbytes, basep)
29int cc, fd;
30char *buf;
31int nbytes;
32long *basep;
33.fi
34.SH DESCRIPTION
35.I Getdirentries
36reads directory entries from the directory
37referenced by the file descriptor
38.I fd
39into the buffer pointed to by
40.IR buf ,
41in a filesystem independent format.
42Up to
43.I nbytes
44of data will be transferred.
45.I Nbytes
46must be greater than or equal to the
47block size associated with the file,
48see
49.IR stat(2) .
50Some filesystems may not support
51.I getdirentries
52with buffers smaller than this size.
53.PP
54The data in the buffer is a series of
55.I dirent
56structures each containing the following entries:
57.PP
58.RS
59.ta +\w'unsigned\0short\0'u +\w'd_name[MAXNAMELEN + 1];\0'u
60.nf
61unsigned long d_fileno;
62unsigned short d_reclen;
63unsigned short d_namlen;
64char d_name[MAXNAMELEN + 1]; /* see below */
65.fi
66.RE
67.PP
68The
69.I d_fileno
70entry is a number which is unique for each
71distinct file in the filesystem.
72Files that are linked by hard links (see
73.IR link(2) )
74have the same
75.IR d_fileno .
76The
77.I d_reclen
78entry is the length, in bytes, of the directory record.
79The
80.I d_name
81entry contains a null terminated file name.
82The
83.I d_namlen
84entry specifies the length of the file name excluding the null byte.
85Thus the actual size of
86.I d_name
87may vary from 1 to \fBMAXNAMELEN + 1\fP.
88.PP
89Entries may be separated by extra space.
90The
91.I d_reclen
92entry may be used as an offset from the start of a
93.I dirent
94structure to the next structure, if any.
95.PP
96The actual number of bytes transferred is returned.
97The current position pointer associated with
98.I fd
99is set to point to the next block of entries.
100The pointer may not advance by the number of bytes returned by
101.IR getdirentries .
102A value of zero is returned when
103the end of the directory has been reached.
104.PP
105.I Getdirentries
106writes the position of the block read into the location pointed to by
107.IR basep .
108Alternatively, the current position pointer may be set and retrieved by
109.IR lseek(2) .
110The current position pointer should only be set to a value returned by
111.I lseek(2) ,
112a value returned in the location pointed to by
113.I basep ,
114or zero.
115.SH RETURN VALUE
116If successful, the number of bytes actually transferred is returned.
117Otherwise, a \-1 is returned and the global variable
118.I errno
119is set to indicate the error.
120.SH ERRORS
121.I Getdirentries
122will fail if one or more of the following are true:
123.TP 15
124EBADF
125\fIfd\fP is not a valid file descriptor open for reading.
126.TP 15
127EFAULT
128Either \fIbuf\fP or \fIbasep\fP point outside the allocated address space.
129.TP 15
130EIO
131An I/O error occurred while reading from or writing to the file system.
132.SH "SEE ALSO"
133open(2), lseek(2)