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