1afe61c15SRodney W. Grimes.\" Copyright (c) 1983, 1991, 1993 2afe61c15SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 3afe61c15SRodney W. Grimes.\" 4afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 5afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions 6afe61c15SRodney W. Grimes.\" are met: 7afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 8afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 9afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 10afe61c15SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 11afe61c15SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 12afe61c15SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 13afe61c15SRodney W. Grimes.\" must display the following acknowledgement: 14afe61c15SRodney W. Grimes.\" This product includes software developed by the University of 15afe61c15SRodney W. Grimes.\" California, Berkeley and its contributors. 16afe61c15SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 17afe61c15SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 18afe61c15SRodney W. Grimes.\" without specific prior written permission. 19afe61c15SRodney W. Grimes.\" 20afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23afe61c15SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30afe61c15SRodney W. Grimes.\" SUCH DAMAGE. 31afe61c15SRodney W. Grimes.\" 32afe61c15SRodney W. Grimes.\" @(#)dir.5 8.3 (Berkeley) 4/19/94 337f3dea24SPeter Wemm.\" $FreeBSD$ 34afe61c15SRodney W. Grimes.\" 35afe61c15SRodney W. Grimes.Dd April 19, 1994 36afe61c15SRodney W. Grimes.Dt DIR 5 37afe61c15SRodney W. Grimes.Os BSD 4.2 38afe61c15SRodney W. Grimes.Sh NAME 39afe61c15SRodney W. Grimes.Nm dir , 40afe61c15SRodney W. Grimes.Nm dirent 41afe61c15SRodney W. Grimes.Nd directory file format 42afe61c15SRodney W. Grimes.Sh SYNOPSIS 43401caa14SBruce Evans.Fd #include <dirent.h> 44afe61c15SRodney W. Grimes.Sh DESCRIPTION 45afe61c15SRodney W. GrimesDirectories provide a convenient hierarchical method of grouping 46afe61c15SRodney W. Grimesfiles while obscuring the underlying details of the storage medium. 47afe61c15SRodney W. GrimesA directory file is differentiated from a plain file 48afe61c15SRodney W. Grimesby a flag in its 49afe61c15SRodney W. Grimes.Xr inode 5 50afe61c15SRodney W. Grimesentry. 51afe61c15SRodney W. GrimesIt consists of records (directory entries) each of which contains 52afe61c15SRodney W. Grimesinformation about a file and a pointer to the file itself. 53afe61c15SRodney W. GrimesDirectory entries may contain other directories 544a8d0283SMike Pritchardas well as plain files; such nested directories are referred to as 55afe61c15SRodney W. Grimessubdirectories. 56afe61c15SRodney W. GrimesA hierarchy of directories and files is formed in this manner 57afe61c15SRodney W. Grimesand is called a file system (or referred to as a file system tree). 58afe61c15SRodney W. Grimes.\" An entry in this tree, 59afe61c15SRodney W. Grimes.\" nested or not nested, 60afe61c15SRodney W. Grimes.\" is a pathname. 61afe61c15SRodney W. Grimes.Pp 62afe61c15SRodney W. GrimesEach directory file contains two special directory entries; one is a pointer 63afe61c15SRodney W. Grimesto the directory itself 64afe61c15SRodney W. Grimescalled dot 653136363fSRuslan Ermilov.Ql .\& 66afe61c15SRodney W. Grimesand the other a pointer to its parent directory called dot-dot 67afe61c15SRodney W. Grimes.Ql \&.. . 68afe61c15SRodney W. GrimesDot and dot-dot 69afe61c15SRodney W. Grimesare valid pathnames, however, 70afe61c15SRodney W. Grimesthe system root directory 71afe61c15SRodney W. Grimes.Ql / , 72afe61c15SRodney W. Grimeshas no parent and dot-dot points to itself like dot. 73afe61c15SRodney W. Grimes.Pp 74afe61c15SRodney W. GrimesFile system nodes are ordinary directory files on which has 75afe61c15SRodney W. Grimesbeen grafted a file system object, such as a physical disk or a 76afe61c15SRodney W. Grimespartitioned area of such a disk. 77afe61c15SRodney W. Grimes(See 78906c1e27SMike Pritchard.Xr mount 2 79afe61c15SRodney W. Grimesand 80afe61c15SRodney W. Grimes.Xr mount 8 . ) 81afe61c15SRodney W. Grimes.Pp 82afe61c15SRodney W. GrimesThe directory entry format is defined in the file 835825b074SBruce Evans.Aq sys/dirent.h 845825b074SBruce Evans(which should not be included directly by applications): 85afe61c15SRodney W. Grimes.Bd -literal 865825b074SBruce Evans#ifndef _SYS_DIRENT_H_ 875825b074SBruce Evans#define _SYS_DIRENT_H_ 88afe61c15SRodney W. Grimes 89b6c7fd53SBruce Evans#include <machine/ansi.h> 90b6c7fd53SBruce Evans 91afe61c15SRodney W. Grimes/* 925825b074SBruce Evans * The dirent structure defines the format of directory entries returned by 935825b074SBruce Evans * the getdirentries(2) system call. 945825b074SBruce Evans * 95afe61c15SRodney W. Grimes * A directory entry has a struct dirent at the front of it, containing its 96afe61c15SRodney W. Grimes * inode number, the length of the entry, and the length of the name 97afe61c15SRodney W. Grimes * contained in the entry. These are followed by the name padded to a 4 98afe61c15SRodney W. Grimes * byte boundary with null bytes. All names are guaranteed null terminated. 99afe61c15SRodney W. Grimes * The maximum length of a name in a directory is MAXNAMLEN. 100afe61c15SRodney W. Grimes */ 101afe61c15SRodney W. Grimes 102afe61c15SRodney W. Grimesstruct dirent { 103b6c7fd53SBruce Evans __uint32_t d_fileno; /* file number of entry */ 104b6c7fd53SBruce Evans __uint16_t d_reclen; /* length of this record */ 105b6c7fd53SBruce Evans __uint8_t d_type; /* file type, see below */ 106b6c7fd53SBruce Evans __uint8_t d_namlen; /* length of string in d_name */ 107afe61c15SRodney W. Grimes#ifdef _POSIX_SOURCE 1085825b074SBruce Evans char d_name[255 + 1]; /* name must be no longer than this */ 109afe61c15SRodney W. Grimes#else 110afe61c15SRodney W. Grimes#define MAXNAMLEN 255 1115825b074SBruce Evans char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ 112afe61c15SRodney W. Grimes#endif 113afe61c15SRodney W. Grimes}; 114afe61c15SRodney W. Grimes 1155f9a0f67SMike Pritchard/* 1165f9a0f67SMike Pritchard * File types 1175f9a0f67SMike Pritchard */ 1185f9a0f67SMike Pritchard#define DT_UNKNOWN 0 1195f9a0f67SMike Pritchard#define DT_FIFO 1 1205f9a0f67SMike Pritchard#define DT_CHR 2 1215f9a0f67SMike Pritchard#define DT_DIR 4 1225f9a0f67SMike Pritchard#define DT_BLK 6 1235f9a0f67SMike Pritchard#define DT_REG 8 1245825b074SBruce Evans#define DT_LNK 10 1255f9a0f67SMike Pritchard#define DT_SOCK 12 1265f9a0f67SMike Pritchard#define DT_WHT 14 1275f9a0f67SMike Pritchard 1285825b074SBruce Evans/* 1295825b074SBruce Evans * Convert between stat structure types and directory types. 1305825b074SBruce Evans */ 1315825b074SBruce Evans#define IFTODT(mode) (((mode) & 0170000) >> 12) 1325825b074SBruce Evans#define DTTOIF(dirtype) ((dirtype) << 12) 133afe61c15SRodney W. Grimes 1345825b074SBruce Evans/* 1355825b074SBruce Evans * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold 1365825b074SBruce Evans * the directory entry. This requires the amount of space in struct direct 1375825b074SBruce Evans * without the d_name field, plus enough space for the name with a terminating 1385825b074SBruce Evans * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. 1395825b074SBruce Evans */ 1405825b074SBruce Evans#define _GENERIC_DIRSIZ(dp) \ 1415825b074SBruce Evans ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) 142afe61c15SRodney W. Grimes 143b6c7fd53SBruce Evans#ifdef _KERNEL 1445825b074SBruce Evans#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) 145afe61c15SRodney W. Grimes#endif 146afe61c15SRodney W. Grimes 1475825b074SBruce Evans#endif /* !_SYS_DIRENT_H_ */ 148afe61c15SRodney W. Grimes.Ed 149afe61c15SRodney W. Grimes.Sh SEE ALSO 150e0e5145cSWolfram Schneider.Xr fs 5 , 151afe61c15SRodney W. Grimes.Xr inode 5 1520de3e154SNik Clayton.Sh BUGS 153b5c508fbSRuslan ErmilovThe usage of the member d_type of struct dirent is unportable as it is 154b5c508fbSRuslan Ermilov.Fx Ns -specific . 1550de3e154SNik ClaytonIt also may fail on certain filesystems, for example the cd9660 filesystem. 156afe61c15SRodney W. Grimes.Sh HISTORY 157afe61c15SRodney W. GrimesA 158afe61c15SRodney W. Grimes.Nm 159afe61c15SRodney W. Grimesfile format appeared in 160afe61c15SRodney W. Grimes.At v7 . 161