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 335825b074SBruce Evans.\" $Id: dir.5,v 1.8 1997/03/19 03:48:12 bde Exp $ 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 43afe61c15SRodney W. Grimes.Fd #include <sys/types.h> 44401caa14SBruce Evans.Fd #include <dirent.h> 45afe61c15SRodney W. Grimes.Sh DESCRIPTION 46afe61c15SRodney W. GrimesDirectories provide a convenient hierarchical method of grouping 47afe61c15SRodney W. Grimesfiles while obscuring the underlying details of the storage medium. 48afe61c15SRodney W. GrimesA directory file is differentiated from a plain file 49afe61c15SRodney W. Grimesby a flag in its 50afe61c15SRodney W. Grimes.Xr inode 5 51afe61c15SRodney W. Grimesentry. 52afe61c15SRodney W. GrimesIt consists of records (directory entries) each of which contains 53afe61c15SRodney W. Grimesinformation about a file and a pointer to the file itself. 54afe61c15SRodney W. GrimesDirectory entries may contain other directories 554a8d0283SMike Pritchardas well as plain files; such nested directories are referred to as 56afe61c15SRodney W. Grimessubdirectories. 57afe61c15SRodney W. GrimesA hierarchy of directories and files is formed in this manner 58afe61c15SRodney W. Grimesand is called a file system (or referred to as a file system tree). 59afe61c15SRodney W. Grimes.\" An entry in this tree, 60afe61c15SRodney W. Grimes.\" nested or not nested, 61afe61c15SRodney W. Grimes.\" is a pathname. 62afe61c15SRodney W. Grimes.Pp 63afe61c15SRodney W. GrimesEach directory file contains two special directory entries; one is a pointer 64afe61c15SRodney W. Grimesto the directory itself 65afe61c15SRodney W. Grimescalled dot 66afe61c15SRodney W. Grimes.Ql \&. 67afe61c15SRodney W. Grimesand the other a pointer to its parent directory called dot-dot 68afe61c15SRodney W. Grimes.Ql \&.. . 69afe61c15SRodney W. GrimesDot and dot-dot 70afe61c15SRodney W. Grimesare valid pathnames, however, 71afe61c15SRodney W. Grimesthe system root directory 72afe61c15SRodney W. Grimes.Ql / , 73afe61c15SRodney W. Grimeshas no parent and dot-dot points to itself like dot. 74afe61c15SRodney W. Grimes.Pp 75afe61c15SRodney W. GrimesFile system nodes are ordinary directory files on which has 76afe61c15SRodney W. Grimesbeen grafted a file system object, such as a physical disk or a 77afe61c15SRodney W. Grimespartitioned area of such a disk. 78afe61c15SRodney W. Grimes(See 79906c1e27SMike Pritchard.Xr mount 2 80afe61c15SRodney W. Grimesand 81afe61c15SRodney W. Grimes.Xr mount 8 . ) 82afe61c15SRodney W. Grimes.Pp 83afe61c15SRodney W. GrimesThe directory entry format is defined in the file 845825b074SBruce Evans.Aq sys/dirent.h 855825b074SBruce Evans(which should not be included directly by applications): 86afe61c15SRodney W. Grimes.Bd -literal 875825b074SBruce Evans#ifndef _SYS_DIRENT_H_ 885825b074SBruce Evans#define _SYS_DIRENT_H_ 89afe61c15SRodney W. Grimes 90afe61c15SRodney W. Grimes/* 915825b074SBruce Evans * The dirent structure defines the format of directory entries returned by 925825b074SBruce Evans * the getdirentries(2) system call. 935825b074SBruce Evans * 94afe61c15SRodney W. Grimes * A directory entry has a struct dirent at the front of it, containing its 95afe61c15SRodney W. Grimes * inode number, the length of the entry, and the length of the name 96afe61c15SRodney W. Grimes * contained in the entry. These are followed by the name padded to a 4 97afe61c15SRodney W. Grimes * byte boundary with null bytes. All names are guaranteed null terminated. 98afe61c15SRodney W. Grimes * The maximum length of a name in a directory is MAXNAMLEN. 99afe61c15SRodney W. Grimes */ 100afe61c15SRodney W. Grimes 101afe61c15SRodney W. Grimesstruct dirent { 1025825b074SBruce Evans u_int32_t d_fileno; /* file number of entry */ 1035825b074SBruce Evans u_int16_t d_reclen; /* length of this record */ 1045825b074SBruce Evans u_int8_t d_type; /* file type, see below */ 1055825b074SBruce Evans u_int8_t d_namlen; /* length of string in d_name */ 106afe61c15SRodney W. Grimes#ifdef _POSIX_SOURCE 1075825b074SBruce Evans char d_name[255 + 1]; /* name must be no longer than this */ 108afe61c15SRodney W. Grimes#else 109afe61c15SRodney W. Grimes#define MAXNAMLEN 255 1105825b074SBruce Evans char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ 111afe61c15SRodney W. Grimes#endif 112afe61c15SRodney W. Grimes}; 113afe61c15SRodney W. Grimes 1145f9a0f67SMike Pritchard/* 1155f9a0f67SMike Pritchard * File types 1165f9a0f67SMike Pritchard */ 1175f9a0f67SMike Pritchard#define DT_UNKNOWN 0 1185f9a0f67SMike Pritchard#define DT_FIFO 1 1195f9a0f67SMike Pritchard#define DT_CHR 2 1205f9a0f67SMike Pritchard#define DT_DIR 4 1215f9a0f67SMike Pritchard#define DT_BLK 6 1225f9a0f67SMike Pritchard#define DT_REG 8 1235825b074SBruce Evans#define DT_LNK 10 1245f9a0f67SMike Pritchard#define DT_SOCK 12 1255f9a0f67SMike Pritchard#define DT_WHT 14 1265f9a0f67SMike Pritchard 1275825b074SBruce Evans/* 1285825b074SBruce Evans * Convert between stat structure types and directory types. 1295825b074SBruce Evans */ 1305825b074SBruce Evans#define IFTODT(mode) (((mode) & 0170000) >> 12) 1315825b074SBruce Evans#define DTTOIF(dirtype) ((dirtype) << 12) 132afe61c15SRodney W. Grimes 1335825b074SBruce Evans/* 1345825b074SBruce Evans * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold 1355825b074SBruce Evans * the directory entry. This requires the amount of space in struct direct 1365825b074SBruce Evans * without the d_name field, plus enough space for the name with a terminating 1375825b074SBruce Evans * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. 1385825b074SBruce Evans */ 1395825b074SBruce Evans#define _GENERIC_DIRSIZ(dp) \ 1405825b074SBruce Evans ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) 141afe61c15SRodney W. Grimes 1425825b074SBruce Evans#ifdef KERNEL 1435825b074SBruce Evans#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) 144afe61c15SRodney W. Grimes#endif 145afe61c15SRodney W. Grimes 1465825b074SBruce Evans#endif /* !_SYS_DIRENT_H_ */ 147afe61c15SRodney W. Grimes.Ed 148afe61c15SRodney W. Grimes.Sh SEE ALSO 149e0e5145cSWolfram Schneider.Xr fs 5 , 150afe61c15SRodney W. Grimes.Xr inode 5 151afe61c15SRodney W. Grimes.Sh HISTORY 152afe61c15SRodney W. GrimesA 153afe61c15SRodney W. Grimes.Nm 154afe61c15SRodney W. Grimesfile format appeared in 155afe61c15SRodney W. Grimes.At v7 . 156