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