1*61609Sbostic.\" Copyright (c) 1983, 1991, 1993 2*61609Sbostic.\" The Regents of the University of California. All rights reserved. 320797Smckusick.\" 448832Scael.\" %sccs.include.redist.man% 520798Smckusick.\" 6*61609Sbostic.\" @(#)dir.5 8.1 (Berkeley) 06/05/93 748832Scael.\" 848832Scael.Dd 948832Scael.Dt DIR 5 1048832Scael.Os BSD 4.2 1148832Scael.Sh NAME 1248832Scael.Nm dir , 1348832Scael.Nm dirent 1448832Scael.Nd directory file format 1548832Scael.Sh SYNOPSIS 1648832Scael.Fd #include <sys/types.h> 1748832Scael.Fd #include <sys/dir.h> 1848832Scael.Sh DESCRIPTION 1948832ScaelDirectories provide a convienent hierarchical method of grouping 2048832Scaelfiles while obscuring the underlying details of the storage medium. 2148832ScaelA directory file is differentiated from a plain file 2248832Scaelby a flag in its 2348832Scael.Xr inode 5 2448832Scaelentry. 2548832ScaelIt consists of records (directory entries) each of which contain 2648832Scaelinformation about a file and a pointer to the file itself. 2748832ScaelDirectory entries may contain other directories 2848832Scaelas well as plain files; such nested directories are refered to as 2948832Scaelsubdirectories. 3048832ScaelA hierarchy of directories and files is formed in this manner 3148832Scaeland is called a file system (or refered to as a file system tree). 3248832Scael.\" An entry in this tree, 3348832Scael.\" nested or not nested, 3448832Scael.\" is a pathname. 3548832Scael.Pp 3648832ScaelEach directory file contains two special directory entries; one is a pointer 3748832Scaelto the directory itself 3848832Scaelcalled dot 3948832Scael.Ql \&. 4048832Scaeland the other a pointer to its parent directory called dot-dot 4148832Scael.Ql \&.. . 4248832ScaelDot and dot-dot 4348832Scaelare valid pathnames, however, 4448832Scaelthe system root directory 4548832Scael.Ql / , 4648832Scaelhas no parent and dot-dot points to itself like dot. 4748832Scael.Pp 4848832ScaelFile system nodes are ordinary directory files on which has 4948832Scaelbeen grafted a file system object, such as a physical disk or a 5048832Scaelpartitioned area of such a disk. 5148832Scael(See 5248832Scael.Xr mount 1 5348832Scaeland 5448832Scael.Xr mount 8 . ) 5548832Scael.Pp 5648832ScaelThe directory entry format is defined in the file 5748832Scael.Aq dirent.h : 5848832Scael.Bd -literal 5948832Scael#ifndef _DIRENT_H_ 6048832Scael#define _DIRENT_H_ 6148832Scael 6220798Smckusick/* 6348832Scael* A directory entry has a struct dirent at the front of it, containing its 6448832Scael* inode number, the length of the entry, and the length of the name 6548832Scael* contained in the entry. These are followed by the name padded to a 4 6648832Scael* byte boundary with null bytes. All names are guaranteed null terminated. 6748832Scael* The maximum length of a name in a directory is MAXNAMLEN. 6848832Scael*/ 6948832Scael 7048832Scaelstruct dirent { 7148832Scael u_long d_fileno; /* file number of entry */ 7248832Scael u_short d_reclen; /* length of this record */ 7348832Scael u_short d_namlen; /* length of string in d_name */ 7448832Scael#ifdef _POSIX_SOURCE 7548832Scael char d_name[MAXNAMLEN + 1]; /* maximum name length */ 7620798Smckusick#else 7748832Scael#define MAXNAMLEN 255 7848832Scael char d_name[MAXNAMLEN + 1]; /* maximum name length */ 7920797Smckusick#endif 8020798Smckusick 8148832Scael}; 8220798Smckusick 8348832Scael#ifdef _POSIX_SOURCE 8448832Scaeltypedef void * DIR; 8548832Scael#else 8620798Smckusick 8748832Scael#define d_ino d_fileno /* backward compatibility */ 8820798Smckusick 8948832Scael/* definitions for library routines operating on directories. */ 9048832Scael#define DIRBLKSIZ 1024 9148832Scael 9248832Scael/* structure describing an open directory. */ 9348832Scaeltypedef struct _dirdesc { 9448832Scael int dd_fd; /* file descriptor associated with directory */ 9548832Scael long dd_loc; /* offset in current buffer */ 9648832Scael long dd_size; /* amount of data returned by getdirentries */ 9748832Scael char *dd_buf; /* data buffer */ 9848832Scael int dd_len; /* size of data buffer */ 9948832Scael long dd_seek; /* magic cookie returned by getdirentries */ 10048832Scael} DIR; 10148832Scael 10248832Scael#define dirfd(dirp) ((dirp)->dd_fd) 10348832Scael 10448832Scael#ifndef NULL 10548832Scael#define NULL 0 10648832Scael#endif 10748832Scael 10848832Scael#endif /* _POSIX_SOURCE */ 10948832Scael 11048832Scael#ifndef KERNEL 11148832Scael 11248832Scael#include <sys/cdefs.h> 11348832Scael 11448832Scael#endif /* !KERNEL */ 11548832Scael 11648832Scael#endif /* !_DIRENT_H_ */ 11748832Scael.Ed 11848832Scael.Sh SEE ALSO 11948832Scael.Xr fs 5 12048832Scael.Xr inode 5 12148832Scael.Sh HISTORY 12248832ScaelA 12348832Scael.Nm 12448832Scaelfile format appeared in 12548832Scael.At v7 . 126