]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getdents.2
getdents.2, readdir.3: d_type is currently only supported on ext[234]
[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 2009-09-29 "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
38 .BI "int getdents(unsigned int " fd ", struct dirent *" dirp ,
39 .BI " unsigned int " count );
40 .fi
41 .SH DESCRIPTION
42 This is not the function you are interested in.
43 Look at
44 .BR readdir (3)
45 for the POSIX conforming C library interface.
46 This page documents the bare kernel system call interface.
47 .PP
48 The system call
49 .BR getdents ()
50 reads several
51 .I dirent
52 structures from the directory
53 referred to by the open file descriptor
54 .I fd
55 into the buffer pointed to by
56 .IR dirp .
57 The argument
58 .I count
59 is the size of the memory area.
60 .PP
61 The
62 .I dirent
63 structure is declared as follows:
64 .PP
65 .in +4n
66 .nf
67 struct linux_dirent {
68 unsigned long d_ino; /* Inode number */
69 unsigned long d_off; /* Offset to next \fIdirent\fP */
70 unsigned short d_reclen; /* Length of this \fIdirent\fP */
71 char d_name []; /* Filename (null-terminated) */
72 /* length is actually (d_reclen \- 2 \-
73 offsetof(struct linux_dirent, d_name) */
74 char pad; /* Zero padding byte */
75 char d_type; /* File type (only since Linux 2.6.4;
76 offset is (d_reclen \- 1)) */
77
78 }
79 .fi
80 .in
81 .PP
82 .I d_ino
83 is an inode number.
84 .I d_off
85 is the distance from the start of the directory to the start of the next
86 .IR dirent .
87 .I d_reclen
88 is the size of this entire
89 .IR dirent .
90 .I d_name
91 is a null-terminated filename.
92
93 .I d_type
94 is a byte at the end of the structure that indicates the file type.
95 It contains one of the following values:
96 .TP 12
97 .B DT_BLK
98 This is a block device.
99 .TP
100 .B DT_CHR
101 This is a character device.
102 .TP
103 .B DT_DIR
104 This is a directory.
105 .TP
106 .B DT_FIFO
107 This is a named pipe (FIFO).
108 .TP
109 .B DT_LNK
110 This is a symbolic link.
111 .TP
112 .B DT_REG
113 This is a regular file.
114 .TP
115 .B DT_SOCK
116 This is a Unix domain socket.
117 .TP
118 .B DT_UNKNOWN
119 The file type is unknown.
120 .PP
121 Curently,
122 .\" kernel 2.6.27
123 only ext2, ext3, and ext4 support returning the file type in
124 .IR d_type .
125 On other file systems,
126 this field is always set to
127 .BR DT_UNKNOWN .
128 .SH "RETURN VALUE"
129 On success, the number of bytes read is returned.
130 On end of directory, 0 is returned.
131 On error, \-1 is returned, and
132 .I errno
133 is set appropriately.
134 .SH ERRORS
135 .TP
136 .B EBADF
137 Invalid file descriptor
138 .IR fd .
139 .TP
140 .B EFAULT
141 Argument points outside the calling process's address space.
142 .TP
143 .B EINVAL
144 Result buffer is too small.
145 .TP
146 .B ENOENT
147 No such directory.
148 .TP
149 .B ENOTDIR
150 File descriptor does not refer to a directory.
151 .SH "CONFORMING TO"
152 SVr4.
153 .\" SVr4 documents additional ENOLINK, EIO error conditions.
154 .SH NOTES
155 Glibc does not provide a wrapper for this system call; call it using
156 .BR syscall (2).
157
158 This call supersedes
159 .BR readdir (2).
160 .SH "SEE ALSO"
161 .BR readdir (2),
162 .BR readdir (3)