1.\" Copyright (c) 1983, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)dir.5 6.2 (Berkeley) 04/29/91 7.\" 8.Dd 9.Dt DIR 5 10.Os BSD 4.2 11.Sh NAME 12.Nm dir , 13.Nm dirent 14.Nd directory file format 15.Sh SYNOPSIS 16.Fd #include <sys/types.h> 17.Fd #include <sys/dir.h> 18.Sh DESCRIPTION 19Directories provide a convienent hierarchical method of grouping 20files while obscuring the underlying details of the storage medium. 21A directory file is differentiated from a plain file 22by a flag in its 23.Xr inode 5 24entry. 25It consists of records (directory entries) each of which contain 26information about a file and a pointer to the file itself. 27Directory entries may contain other directories 28as well as plain files; such nested directories are refered to as 29subdirectories. 30A hierarchy of directories and files is formed in this manner 31and is called a file system (or refered to as a file system tree). 32.\" An entry in this tree, 33.\" nested or not nested, 34.\" is a pathname. 35.Pp 36Each directory file contains two special directory entries; one is a pointer 37to the directory itself 38called dot 39.Ql \&. 40and the other a pointer to its parent directory called dot-dot 41.Ql \&.. . 42Dot and dot-dot 43are valid pathnames, however, 44the system root directory 45.Ql / , 46has no parent and dot-dot points to itself like dot. 47.Pp 48File system nodes are ordinary directory files on which has 49been grafted a file system object, such as a physical disk or a 50partitioned area of such a disk. 51(See 52.Xr mount 1 53and 54.Xr mount 8 . ) 55.Pp 56The directory entry format is defined in the file 57.Aq dirent.h : 58.Bd -literal 59#ifndef _DIRENT_H_ 60#define _DIRENT_H_ 61 62/* 63* A directory entry has a struct dirent at the front of it, containing its 64* inode number, the length of the entry, and the length of the name 65* contained in the entry. These are followed by the name padded to a 4 66* byte boundary with null bytes. All names are guaranteed null terminated. 67* The maximum length of a name in a directory is MAXNAMLEN. 68*/ 69 70struct dirent { 71 u_long d_fileno; /* file number of entry */ 72 u_short d_reclen; /* length of this record */ 73 u_short d_namlen; /* length of string in d_name */ 74#ifdef _POSIX_SOURCE 75 char d_name[MAXNAMLEN + 1]; /* maximum name length */ 76#else 77#define MAXNAMLEN 255 78 char d_name[MAXNAMLEN + 1]; /* maximum name length */ 79#endif 80 81}; 82 83#ifdef _POSIX_SOURCE 84typedef void * DIR; 85#else 86 87#define d_ino d_fileno /* backward compatibility */ 88 89/* definitions for library routines operating on directories. */ 90#define DIRBLKSIZ 1024 91 92/* structure describing an open directory. */ 93typedef struct _dirdesc { 94 int dd_fd; /* file descriptor associated with directory */ 95 long dd_loc; /* offset in current buffer */ 96 long dd_size; /* amount of data returned by getdirentries */ 97 char *dd_buf; /* data buffer */ 98 int dd_len; /* size of data buffer */ 99 long dd_seek; /* magic cookie returned by getdirentries */ 100} DIR; 101 102#define dirfd(dirp) ((dirp)->dd_fd) 103 104#ifndef NULL 105#define NULL 0 106#endif 107 108#endif /* _POSIX_SOURCE */ 109 110#ifndef KERNEL 111 112#include <sys/cdefs.h> 113 114#endif /* !KERNEL */ 115 116#endif /* !_DIRENT_H_ */ 117.Ed 118.Sh SEE ALSO 119.Xr fs 5 120.Xr inode 5 121.Sh HISTORY 122A 123.Nm 124file format appeared in 125.At v7 . 126