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