Debian Codegraph @

upstream/debian-trixie/man2/readdir.2

raw
1 .\" Copyright (C) 1995 Andries Brouwer ([email protected])
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" Written 11 June 1995 by Andries Brouwer <[email protected]>
6 .\" Modified 22 July 1995 by Michael Chastain <[email protected]>:
7 .\" In 1.3.X, returns only one entry each time; return value is different.
8 .\" Modified 2004-12-01, mtk, fixed headers listed in SYNOPSIS
9 .\"
10 .TH readdir 2 2024-06-15 "Linux man-pages 6.9.1"
11 .SH NAME
12 readdir \- read directory entry
13 .SH LIBRARY
14 Standard C library
15 .RI ( libc ", " \-lc )
16 .SH SYNOPSIS
17 .nf
18 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
19 .B #include <unistd.h>
20 .P
21 .BI "int syscall(SYS_readdir, unsigned int " fd ,
22 .BI " struct old_linux_dirent *" dirp ", unsigned int " count );
23 .fi
24 .P
25 .IR Note :
26 There is no definition of
27 .BR "struct old_linux_dirent" ;
28 see NOTES.
29 .SH DESCRIPTION
30 This is not the function you are interested in.
31 Look at
32 .BR readdir (3)
33 for the POSIX conforming C library interface.
34 This page documents the bare kernel system call interface,
35 which is superseded by
36 .BR getdents (2).
37 .P
38 .BR readdir ()
39 reads one
40 .I old_linux_dirent
41 structure from the directory
42 referred to by the file descriptor
43 .I fd
44 into the buffer pointed to by
45 .IR dirp .
46 The argument
47 .I count
48 is ignored; at most one
49 .I old_linux_dirent
50 structure is read.
51 .P
52 The
53 .I old_linux_dirent
54 structure is declared (privately in Linux kernel file
55 .BR fs/readdir.c )
56 as follows:
57 .P
58 .in +4n
59 .EX
60 struct old_linux_dirent {
61 unsigned long d_ino; /* inode number */
62 unsigned long d_offset; /* offset to this \fIold_linux_dirent\fP */
63 unsigned short d_namlen; /* length of this \fId_name\fP */
64 char d_name[1]; /* filename (null\-terminated) */
65 }
66 .EE
67 .in
68 .P
69 .I d_ino
70 is an inode number.
71 .I d_offset
72 is the distance from the start of the directory to this
73 .IR old_linux_dirent .
74 .I d_reclen
75 is the size of
76 .IR d_name ,
77 not counting the terminating null byte (\[aq]\[rs]0\[aq]).
78 .I d_name
79 is a null-terminated filename.
80 .SH RETURN VALUE
81 On success, 1 is returned.
82 On end of directory, 0 is returned.
83 On error, \-1 is returned, and
84 .I errno
85 is set to indicate the error.
86 .SH ERRORS
87 .TP
88 .B EBADF
89 Invalid file descriptor
90 .IR fd .
91 .TP
92 .B EFAULT
93 Argument points outside the calling process's address space.
94 .TP
95 .B EINVAL
96 Result buffer is too small.
97 .TP
98 .B ENOENT
99 No such directory.
100 .TP
101 .B ENOTDIR
102 File descriptor does not refer to a directory.
103 .SH VERSIONS
104 You will need to define the
105 .I old_linux_dirent
106 structure yourself.
107 However, probably you should use
108 .BR readdir (3)
109 instead.
110 .P
111 This system call does not exist on x86-64.
112 .SH STANDARDS
113 Linux.
114 .SH SEE ALSO
115 .BR getdents (2),
116 .BR readdir (3)