1.\" $OpenBSD: dir.5,v 1.8 2000/10/26 00:37:04 aaron Exp $ 2.\" $NetBSD: dir.5,v 1.5 1995/03/28 17:30:20 jtc Exp $ 3.\" 4.\" Copyright (c) 1983, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)dir.5 8.3 (Berkeley) 4/19/94 36.\" 37.Dd April 19, 1994 38.Dt DIR 5 39.Os 40.Sh NAME 41.Nm dir , 42.Nm dirent 43.Nd directory file format 44.Sh SYNOPSIS 45.Fd #include <sys/types.h> 46.Fd #include <sys/dir.h> 47.Sh DESCRIPTION 48Directories provide a convenient hierarchical method of grouping 49files while obscuring the underlying details of the storage medium. 50A directory file is differentiated from a plain file by a flag in its 51.Xr inode 5 52entry. 53It consists of records (directory entries) each of which contains 54information about a file and a pointer to the file itself. 55Directory entries may contain other directories as well as plain files; 56such nested directories are referred to as subdirectories. 57A hierarchy of directories and files is formed in this manner 58and is called a file system (or referred to as a file system tree). 59.\" An entry in this tree, 60.\" nested or not nested, 61.\" is a pathname. 62.Pp 63Each directory file contains two special directory entries; one is a pointer 64to the directory itself called dot 65.Pq Dq \&. 66and the other a pointer to its parent directory called dot-dot 67.Pq Dq \&.. . 68Dot and dot-dot are valid pathnames, however, the system root directory 69.Pq Dq / , 70has no parent and dot-dot points to itself like dot. 71.Pp 72File system nodes are ordinary directory files on which has 73been grafted a file system object, such as a physical disk or a 74partitioned area of such a disk (see 75.Xr mount 8 ) . 76.Pp 77The directory entry format is defined in the file 78.Aq Pa dirent.h : 79.Bd -literal 80#ifndef _DIRENT_H_ 81#define _DIRENT_H_ 82 83/* 84* A directory entry has a struct dirent at the front of it, containing its 85* inode number, the length of the entry, and the length of the name 86* contained in the entry. These are followed by the name padded to a 4 87* byte boundary with null bytes. All names are guaranteed null terminated. 88* The maximum length of a name in a directory is MAXNAMLEN. 89*/ 90 91struct dirent { 92 u_long d_fileno; /* file number of entry */ 93 u_short d_reclen; /* length of this record */ 94 u_short d_namlen; /* length of string in d_name */ 95#ifdef _POSIX_SOURCE 96 char d_name[MAXNAMLEN + 1]; /* maximum name length */ 97#else 98#define MAXNAMLEN 255 99 char d_name[MAXNAMLEN + 1]; /* maximum name length */ 100#endif 101 102}; 103 104#ifdef _POSIX_SOURCE 105typedef void * DIR; 106#else 107 108#define d_ino d_fileno /* backward compatibility */ 109 110/* definitions for library routines operating on directories. */ 111#define DIRBLKSIZ 1024 112 113/* structure describing an open directory. */ 114typedef struct _dirdesc { 115 int dd_fd; /* file descriptor associated with directory */ 116 long dd_loc; /* offset in current buffer */ 117 long dd_size; /* amount of data returned by getdirentries */ 118 char *dd_buf; /* data buffer */ 119 int dd_len; /* size of data buffer */ 120 long dd_seek; /* magic cookie returned by getdirentries */ 121} DIR; 122 123#define dirfd(dirp) ((dirp)->dd_fd) 124 125#ifndef NULL 126#define NULL 0 127#endif 128 129#endif /* _POSIX_SOURCE */ 130 131#ifndef _KERNEL 132 133#include <sys/cdefs.h> 134 135#endif /* !_KERNEL */ 136 137#endif /* !_DIRENT_H_ */ 138.Ed 139.Sh SEE ALSO 140.Xr fs 5 , 141.Xr inode 5 142.Sh HISTORY 143A 144.Nm dir 145file format appeared in 146.At v7 . 147