GETDENTS(2) Linux Programmers Manual GETDENTS(2)
NAME
getdents - get directory entries
SYNOPSIS
#include
#include
#include
#include
#include
int getdents(unsigned int fd, struct dirent *dirp,
unsigned int count);
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 dirent structures from the
directory referred to by the open file descriptor fd into the buffer
pointed to by dirp. The argument count is the size of the memory area.
The dirent structure is declared as follows:
struct linux_dirent {
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Offset to next dirent */
unsigned short d_reclen; /* Length of this dirent */
char d_name []; /* Filename (null-terminated) */
/* length is actually (d_reclen - 2 -
offsetof(struct linux_dirent, d_name) */
char pad; /* Zero padding byte */
char d_type; /* File type (only since Linux 2.6.4;
offset is (d_reclen - 1)) */
}
d_ino is an inode number. d_off is the distance from the start of the
directory to the start of the next dirent. d_reclen is the size of
this entire 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:
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.
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 processs 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).
This call supersedes readdir(2).
SEE ALSO
readdir(2), readdir(3)
COLOPHON
This page is part of release 3.05 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-06-22 GETDENTS(2)
|