1*bbb1b6f9SApple OSS Distributions.\" $NetBSD: dir.5,v 1.5 1995/03/28 17:30:20 jtc Exp $ 2*bbb1b6f9SApple OSS Distributions.\" 3*bbb1b6f9SApple OSS Distributions.\" Copyright (c) 1983, 1991, 1993 4*bbb1b6f9SApple OSS Distributions.\" The Regents of the University of California. All rights reserved. 5*bbb1b6f9SApple OSS Distributions.\" 6*bbb1b6f9SApple OSS Distributions.\" Redistribution and use in source and binary forms, with or without 7*bbb1b6f9SApple OSS Distributions.\" modification, are permitted provided that the following conditions 8*bbb1b6f9SApple OSS Distributions.\" are met: 9*bbb1b6f9SApple OSS Distributions.\" 1. Redistributions of source code must retain the above copyright 10*bbb1b6f9SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer. 11*bbb1b6f9SApple OSS Distributions.\" 2. Redistributions in binary form must reproduce the above copyright 12*bbb1b6f9SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer in the 13*bbb1b6f9SApple OSS Distributions.\" documentation and/or other materials provided with the distribution. 14*bbb1b6f9SApple OSS Distributions.\" 3. All advertising materials mentioning features or use of this software 15*bbb1b6f9SApple OSS Distributions.\" must display the following acknowledgement: 16*bbb1b6f9SApple OSS Distributions.\" This product includes software developed by the University of 17*bbb1b6f9SApple OSS Distributions.\" California, Berkeley and its contributors. 18*bbb1b6f9SApple OSS Distributions.\" 4. Neither the name of the University nor the names of its contributors 19*bbb1b6f9SApple OSS Distributions.\" may be used to endorse or promote products derived from this software 20*bbb1b6f9SApple OSS Distributions.\" without specific prior written permission. 21*bbb1b6f9SApple OSS Distributions.\" 22*bbb1b6f9SApple OSS Distributions.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*bbb1b6f9SApple OSS Distributions.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*bbb1b6f9SApple OSS Distributions.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*bbb1b6f9SApple OSS Distributions.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*bbb1b6f9SApple OSS Distributions.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*bbb1b6f9SApple OSS Distributions.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*bbb1b6f9SApple OSS Distributions.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*bbb1b6f9SApple OSS Distributions.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*bbb1b6f9SApple OSS Distributions.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*bbb1b6f9SApple OSS Distributions.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*bbb1b6f9SApple OSS Distributions.\" SUCH DAMAGE. 33*bbb1b6f9SApple OSS Distributions.\" 34*bbb1b6f9SApple OSS Distributions.\" @(#)dir.5 8.3 (Berkeley) 4/19/94 35*bbb1b6f9SApple OSS Distributions.\" 36*bbb1b6f9SApple OSS Distributions.Dd April 19, 1994 37*bbb1b6f9SApple OSS Distributions.Dt DIR 5 38*bbb1b6f9SApple OSS Distributions.Os BSD 4.2 39*bbb1b6f9SApple OSS Distributions.Sh NAME 40*bbb1b6f9SApple OSS Distributions.Nm dir , 41*bbb1b6f9SApple OSS Distributions.Nm dirent 42*bbb1b6f9SApple OSS Distributions.Nd directory file format 43*bbb1b6f9SApple OSS Distributions.Sh SYNOPSIS 44*bbb1b6f9SApple OSS Distributions.Fd #include <sys/types.h> 45*bbb1b6f9SApple OSS Distributions.Fd #include <sys/dir.h> 46*bbb1b6f9SApple OSS Distributions.Sh DESCRIPTION 47*bbb1b6f9SApple OSS DistributionsDirectories provide a convenient hierarchical method of grouping 48*bbb1b6f9SApple OSS Distributionsfiles while obscuring the underlying details of the storage medium. 49*bbb1b6f9SApple OSS DistributionsA directory file is differentiated from a plain file 50*bbb1b6f9SApple OSS Distributionsby a flag in its 51*bbb1b6f9SApple OSS Distributions.Xr inode 5 52*bbb1b6f9SApple OSS Distributionsentry. 53*bbb1b6f9SApple OSS DistributionsIt consists of records (directory entries) each of which contains 54*bbb1b6f9SApple OSS Distributionsinformation about a file and a pointer to the file itself. 55*bbb1b6f9SApple OSS DistributionsDirectory entries may contain other directories 56*bbb1b6f9SApple OSS Distributionsas well as plain files; such nested directories are refered to as 57*bbb1b6f9SApple OSS Distributionssubdirectories. 58*bbb1b6f9SApple OSS DistributionsA hierarchy of directories and files is formed in this manner 59*bbb1b6f9SApple OSS Distributionsand is called a file system (or referred to as a file system tree). 60*bbb1b6f9SApple OSS Distributions.\" An entry in this tree, 61*bbb1b6f9SApple OSS Distributions.\" nested or not nested, 62*bbb1b6f9SApple OSS Distributions.\" is a pathname. 63*bbb1b6f9SApple OSS Distributions.Pp 64*bbb1b6f9SApple OSS DistributionsEach directory file contains two special directory entries; one is a pointer 65*bbb1b6f9SApple OSS Distributionsto the directory itself 66*bbb1b6f9SApple OSS Distributionscalled dot 67*bbb1b6f9SApple OSS Distributions.Ql \&. 68*bbb1b6f9SApple OSS Distributionsand the other a pointer to its parent directory called dot-dot 69*bbb1b6f9SApple OSS Distributions.Ql \&.. . 70*bbb1b6f9SApple OSS DistributionsDot and dot-dot 71*bbb1b6f9SApple OSS Distributionsare valid pathnames, however, 72*bbb1b6f9SApple OSS Distributionsthe system root directory 73*bbb1b6f9SApple OSS Distributions.Ql / , 74*bbb1b6f9SApple OSS Distributionshas no parent and dot-dot points to itself like dot. 75*bbb1b6f9SApple OSS Distributions.Pp 76*bbb1b6f9SApple OSS DistributionsFile system nodes are ordinary directory files on which has 77*bbb1b6f9SApple OSS Distributionsbeen grafted a file system object, such as a physical disk or a 78*bbb1b6f9SApple OSS Distributionspartitioned area of such a disk. 79*bbb1b6f9SApple OSS Distributions(See 80*bbb1b6f9SApple OSS Distributions.Xr mount 1 81*bbb1b6f9SApple OSS Distributionsand 82*bbb1b6f9SApple OSS Distributions.Xr mount 8 . ) 83*bbb1b6f9SApple OSS Distributions.Pp 84*bbb1b6f9SApple OSS DistributionsThe directory entry format is defined in the file 85*bbb1b6f9SApple OSS Distributions.Aq sys/dirent.h 86*bbb1b6f9SApple OSS Distributionsand further in the file 87*bbb1b6f9SApple OSS Distributions.Aq dirent.h . 88*bbb1b6f9SApple OSS DistributionsWhen the macro 89*bbb1b6f9SApple OSS Distributions.Dv _DARWIN_FEATURE_64_BIT_INODE 90*bbb1b6f9SApple OSS Distributionsis not defined (see 91*bbb1b6f9SApple OSS Distributions.Xr stat 2 92*bbb1b6f9SApple OSS Distributionsfor more information on this macro), the 93*bbb1b6f9SApple OSS Distributions.Fa dirent 94*bbb1b6f9SApple OSS Distributionsstructure is defined as: 95*bbb1b6f9SApple OSS Distributions.Bd -literal 96*bbb1b6f9SApple OSS Distributions/*** Excerpt from <sys/dirent.h> ***/ 97*bbb1b6f9SApple OSS Distributions/* 98*bbb1b6f9SApple OSS Distributions * The dirent structure defines the format of directory entries. 99*bbb1b6f9SApple OSS Distributions * 100*bbb1b6f9SApple OSS Distributions * A directory entry has a struct dirent at the front of it, containing its 101*bbb1b6f9SApple OSS Distributions * inode number, the length of the entry, and the length of the name 102*bbb1b6f9SApple OSS Distributions * contained in the entry. These are followed by the name padded to a 4 103*bbb1b6f9SApple OSS Distributions * byte boundary with null bytes. All names are guaranteed null terminated. 104*bbb1b6f9SApple OSS Distributions * The maximum length of a name in a directory is 255. 105*bbb1b6f9SApple OSS Distributions */ 106*bbb1b6f9SApple OSS Distributions 107*bbb1b6f9SApple OSS Distributionsstruct dirent { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */ 108*bbb1b6f9SApple OSS Distributions ino_t d_ino; /* file number of entry */ 109*bbb1b6f9SApple OSS Distributions __uint16_t d_reclen; /* length of this record */ 110*bbb1b6f9SApple OSS Distributions __uint8_t d_type; /* file type, see below */ 111*bbb1b6f9SApple OSS Distributions __uint8_t d_namlen; /* length of string in d_name */ 112*bbb1b6f9SApple OSS Distributions char d_name[255 + 1]; /* name must be no longer than this */ 113*bbb1b6f9SApple OSS Distributions}; 114*bbb1b6f9SApple OSS Distributions.Ed 115*bbb1b6f9SApple OSS Distributions.Pp 116*bbb1b6f9SApple OSS DistributionsHowever, when the macro 117*bbb1b6f9SApple OSS Distributions.Dv _DARWIN_FEATURE_64_BIT_INODE 118*bbb1b6f9SApple OSS Distributionsis defined, the 119*bbb1b6f9SApple OSS Distributions.Fa dirent 120*bbb1b6f9SApple OSS Distributionsstructure is defined as: 121*bbb1b6f9SApple OSS Distributions.Bd -literal 122*bbb1b6f9SApple OSS Distributions/* 123*bbb1b6f9SApple OSS Distributions * The dirent structure defines the format of directory entries. 124*bbb1b6f9SApple OSS Distributions * 125*bbb1b6f9SApple OSS Distributions * A directory entry has a struct dirent at the front of it, containing its 126*bbb1b6f9SApple OSS Distributions * inode number, the length of the entry, and the length of the name 127*bbb1b6f9SApple OSS Distributions * contained in the entry. These are followed by the name padded to a 4 128*bbb1b6f9SApple OSS Distributions * byte boundary with null bytes. All names are guaranteed null terminated. 129*bbb1b6f9SApple OSS Distributions * The maximum length of a name in a directory is 1023. 130*bbb1b6f9SApple OSS Distributions */ 131*bbb1b6f9SApple OSS Distributions 132*bbb1b6f9SApple OSS Distributionsstruct dirent { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */ 133*bbb1b6f9SApple OSS Distributions ino_t d_fileno; /* file number of entry */ 134*bbb1b6f9SApple OSS Distributions __uint64_t d_seekoff; /* seek offset (optional, used by servers) */ 135*bbb1b6f9SApple OSS Distributions __uint16_t d_reclen; /* length of this record */ 136*bbb1b6f9SApple OSS Distributions __uint16_t d_namlen; /* length of string in d_name */ 137*bbb1b6f9SApple OSS Distributions __uint8_t d_type; /* file type, see below */ 138*bbb1b6f9SApple OSS Distributions char d_name[1024]; /* name must be no longer than this */ 139*bbb1b6f9SApple OSS Distributions}; 140*bbb1b6f9SApple OSS Distributions.Ed 141*bbb1b6f9SApple OSS Distributions.Pp 142*bbb1b6f9SApple OSS DistributionsIn addition: 143*bbb1b6f9SApple OSS Distributions.Bd -literal 144*bbb1b6f9SApple OSS Distributions/* 145*bbb1b6f9SApple OSS Distributions * File types 146*bbb1b6f9SApple OSS Distributions */ 147*bbb1b6f9SApple OSS Distributions#define DT_UNKNOWN 0 148*bbb1b6f9SApple OSS Distributions#define DT_FIFO 1 149*bbb1b6f9SApple OSS Distributions#define DT_CHR 2 150*bbb1b6f9SApple OSS Distributions#define DT_DIR 4 151*bbb1b6f9SApple OSS Distributions#define DT_BLK 6 152*bbb1b6f9SApple OSS Distributions#define DT_REG 8 153*bbb1b6f9SApple OSS Distributions#define DT_LNK 10 154*bbb1b6f9SApple OSS Distributions#define DT_SOCK 12 155*bbb1b6f9SApple OSS Distributions#define DT_WHT 14 156*bbb1b6f9SApple OSS Distributions 157*bbb1b6f9SApple OSS Distributions.Ed 158*bbb1b6f9SApple OSS Distributions----------------------------------------- 159*bbb1b6f9SApple OSS Distributions.Bd -literal 160*bbb1b6f9SApple OSS Distributions/*** Excerpt from <dirent.h> ***/ 161*bbb1b6f9SApple OSS Distributions 162*bbb1b6f9SApple OSS Distributions#define d_fileno d_ino /* backward compatibility */ 163*bbb1b6f9SApple OSS Distributions 164*bbb1b6f9SApple OSS Distributions/* definitions for library routines operating on directories. */ 165*bbb1b6f9SApple OSS Distributions#define DIRBLKSIZ 1024 166*bbb1b6f9SApple OSS Distributions 167*bbb1b6f9SApple OSS Distributionsstruct _telldir; /* see telldir.h */ 168*bbb1b6f9SApple OSS Distributions 169*bbb1b6f9SApple OSS Distributions/* structure describing an open directory. */ 170*bbb1b6f9SApple OSS Distributionstypedef struct _dirdesc { 171*bbb1b6f9SApple OSS Distributions int __dd_fd; /* file descriptor associated with directory */ 172*bbb1b6f9SApple OSS Distributions long __dd_loc; /* offset in current buffer */ 173*bbb1b6f9SApple OSS Distributions long __dd_size; /* amount of data returned by getdirentries */ 174*bbb1b6f9SApple OSS Distributions char *__dd_buf; /* data buffer */ 175*bbb1b6f9SApple OSS Distributions int __dd_len; /* size of data buffer */ 176*bbb1b6f9SApple OSS Distributions long __dd_seek; /* magic cookie returned by getdirentries */ 177*bbb1b6f9SApple OSS Distributions long __dd_rewind; /* magic cookie for rewinding */ 178*bbb1b6f9SApple OSS Distributions int __dd_flags; /* flags for readdir */ 179*bbb1b6f9SApple OSS Distributions pthread_mutex_t __dd_lock; /* for thread locking */ 180*bbb1b6f9SApple OSS Distributions struct _telldir *__dd_td; /* telldir position recording */ 181*bbb1b6f9SApple OSS Distributions} DIR; 182*bbb1b6f9SApple OSS Distributions 183*bbb1b6f9SApple OSS Distributions#define dirfd(dirp) ((dirp)->dd_fd) 184*bbb1b6f9SApple OSS Distributions 185*bbb1b6f9SApple OSS Distributions/* flags for opendir2 */ 186*bbb1b6f9SApple OSS Distributions#define DTF_HIDEW 0x0001 /* hide whiteout entries */ 187*bbb1b6f9SApple OSS Distributions#define DTF_NODUP 0x0002 /* don't return duplicate names */ 188*bbb1b6f9SApple OSS Distributions#define DTF_REWIND 0x0004 /* rewind after reading union stack */ 189*bbb1b6f9SApple OSS Distributions#define __DTF_READALL 0x0008 /* everything has been read */ 190*bbb1b6f9SApple OSS Distributions.Ed 191*bbb1b6f9SApple OSS Distributions.Sh SEE ALSO 192*bbb1b6f9SApple OSS Distributions.Xr fs 5 , 193*bbb1b6f9SApple OSS Distributions.Xr inode 5 194*bbb1b6f9SApple OSS Distributions.Sh HISTORY 195*bbb1b6f9SApple OSS DistributionsA 196*bbb1b6f9SApple OSS Distributions.Nm 197*bbb1b6f9SApple OSS Distributionsfile format appeared in 198*bbb1b6f9SApple OSS Distributions.At v7 . 199