]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getdents.2
ffixes
[thirdparty/man-pages.git] / man2 / getdents.2
1 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
24 .\" Modified 22 July 1995 by Michael Chastain <mec@duracef.shout.net>:
25 .\" Derived from 'readdir.2'.
26 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .TH GETDENTS 2 2008-06-22 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 getdents \- get directory entries
30 .SH SYNOPSIS
31 .nf
32 .B #include <unistd.h>
33 .B #include <linux/types.h>
34 .B #include <linux/dirent.h>
35 .B #include <linux/unistd.h>
36 .B #include <errno.h>
37 .sp
38 .BI "int getdents(unsigned int " fd ", struct dirent *" dirp ", unsigned int " count );
39 .fi
40 .SH DESCRIPTION
41 This is not the function you are interested in.
42 Look at
43 .BR readdir (3)
44 for the POSIX conforming C library interface.
45 This page documents the bare kernel system call interface.
46 .PP
47 The system call
48 .BR getdents ()
49 reads several
50 .I dirent
51 structures from the directory
52 referred to by the open file descriptor
53 .I fd
54 into the buffer pointed to by
55 .IR dirp .
56 The parameter
57 .I count
58 is the size of the memory area.
59 .PP
60 The
61 .I dirent
62 structure is declared as follows:
63 .PP
64 .in +4n
65 .nf
66 struct linux_dirent {
67 unsigned long d_ino; /* Inode number */
68 unsigned long d_off; /* Offset to next \fIdirent\fP */
69 unsigned short d_reclen; /* Length of this \fIdirent\fP */
70 char d_name []; /* Filename (null-terminated) */
71 /* length is actually (d_reclen \- 2 \-
72 offsetof(struct linux_dirent, d_name) */
73 /* char pad; Zero padding byte */
74 /* char d_type; File type (only since Linux 2.6.4;
75 offset is (d_reclen \- 1)) */
76
77 }
78 .fi
79 .in
80 .PP
81 .I d_ino
82 is an inode number.
83 .I d_off
84 is the distance from the start of the directory to the start of the next
85 .IR dirent .
86 .I d_reclen
87 is the size of this entire
88 .IR dirent .
89 .I d_name
90 is a null-terminated filename.
91
92 .I d_type
93 is a byte at the end of the structure that indicates the file type.
94 It returns one of the following values:
95 .TP 12
96 .B DT_BLK
97 This is a block device.
98 .TP
99 .B DT_CHR
100 This is a character device.
101 .TP
102 .B DT_DIR
103 This is a directory.
104 .TP
105 .B DT_FIFO
106 This is a named pipe (FIFO).
107 .TP
108 .B DT_LNK
109 This is a symbolic link.
110 .TP
111 .B DT_REG
112 This is a regular file.
113 .TP
114 .B DT_SOCK
115 This is a Unix domain socket.
116 .TP
117 .B DT_UNKNOWN
118 The file type is unknown.
119 .SH "RETURN VALUE"
120 On success, the number of bytes read is returned.
121 On end of directory, 0 is returned.
122 On error, \-1 is returned, and
123 .I errno
124 is set appropriately.
125 .SH ERRORS
126 .TP
127 .B EBADF
128 Invalid file descriptor
129 .IR fd .
130 .TP
131 .B EFAULT
132 Argument points outside the calling process's address space.
133 .TP
134 .B EINVAL
135 Result buffer is too small.
136 .TP
137 .B ENOENT
138 No such directory.
139 .TP
140 .B ENOTDIR
141 File descriptor does not refer to a directory.
142 .SH "CONFORMING TO"
143 SVr4.
144 .\" SVr4 documents additional ENOLINK, EIO error conditions.
145 .SH NOTES
146 Glibc does not provide a wrapper for this system call; call it using
147 .BR syscall (2).
148
149 This call supersedes
150 .BR readdir (2).
151 .SH "SEE ALSO"
152 .BR readdir (2),
153 .BR readdir (3)