NAME

SYNOPSIS

DESCRIPTION

This is not the function you are interested in.
Look at
readdir(3)
for the POSIX conforming C library interface.
This page documents the bare kernel system call interface.

The system call
getdents()
reads several
linux_dirent
structures from the directory
referred to by the open file descriptor
fd
into the buffer pointed to by
dirp.
The argument
count
specifies the size of that buffer.

d_ino
is an inode number.
d_off
is the distance from the start of the directory to the start of the next
linux_dirent.
d_reclen
is the size of this entire
linux_dirent.
d_name
is a null-terminated filename.

d_type
is a byte at the end of the structure that indicates the file type.
It contains one of the following values (defined in
<dirent.h>):

DT_BLK

This is a block device.

DT_CHR

This is a character device.

DT_DIR

This is a directory.

DT_FIFO

This is a named pipe (FIFO).

DT_LNK

This is a symbolic link.

DT_REG

This is a regular file.

DT_SOCK

This is a Unix domain socket.

DT_UNKNOWN

The file type is unknown.

The
d_type
field is implemented since Linux 2.6.4.
It occupies a space that was previously a zero-filled padding byte in the
linux_dirent
structure.
Thus, on kernels before 2.6.3,
attempting to access this field always provides the value 0
(DT_UNKNOWN).

Currently,
only some file systems (among them: ext2, etx3, and ext4)
have full support for returning the file type in
d_type.
All applications must properly handle a return of
DT_UNKNOWN.

RETURN VALUE

On success, the number of bytes read is returned.
On end of directory, 0 is returned.
On error, -1 is returned, and
errno
is set appropriately.

ERRORS

EBADF

Invalid file descriptor
fd.

EFAULT

Argument points outside the calling process's address space.

EINVAL

Result buffer is too small.

ENOENT

No such directory.

ENOTDIR

File descriptor does not refer to a directory.

CONFORMING TO

SVr4.

NOTES

Glibc does not provide a wrapper for this system call; call it using
syscall(2).
You will need to define the
linux_dirent
structure yourself.