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 33afe61c15SRodney W. Grimes.\" 34afe61c15SRodney W. Grimes.Dd April 19, 1994 35afe61c15SRodney W. Grimes.Dt DIR 5 36afe61c15SRodney W. Grimes.Os BSD 4.2 37afe61c15SRodney W. Grimes.Sh NAME 38afe61c15SRodney W. Grimes.Nm dir , 39afe61c15SRodney W. Grimes.Nm dirent 40afe61c15SRodney W. Grimes.Nd directory file format 41afe61c15SRodney W. Grimes.Sh SYNOPSIS 42afe61c15SRodney W. Grimes.Fd #include <sys/types.h> 43afe61c15SRodney W. Grimes.Fd #include <sys/dir.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 54afe61c15SRodney W. Grimesas well as plain files; such nested directories are refered 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 65afe61c15SRodney W. Grimes.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 78afe61c15SRodney W. Grimes.Xr mount 1 79afe61c15SRodney W. Grimesand 80afe61c15SRodney W. Grimes.Xr mount 8 . ) 81afe61c15SRodney W. Grimes.Pp 82afe61c15SRodney W. GrimesThe directory entry format is defined in the file 83afe61c15SRodney W. Grimes.Aq dirent.h : 84afe61c15SRodney W. Grimes.Bd -literal 85afe61c15SRodney W. Grimes#ifndef _DIRENT_H_ 86afe61c15SRodney W. Grimes#define _DIRENT_H_ 87afe61c15SRodney W. Grimes 88afe61c15SRodney W. Grimes/* 89afe61c15SRodney W. Grimes* A directory entry has a struct dirent at the front of it, containing its 90afe61c15SRodney W. Grimes* inode number, the length of the entry, and the length of the name 91afe61c15SRodney W. Grimes* contained in the entry. These are followed by the name padded to a 4 92afe61c15SRodney W. Grimes* byte boundary with null bytes. All names are guaranteed null terminated. 93afe61c15SRodney W. Grimes* The maximum length of a name in a directory is MAXNAMLEN. 94afe61c15SRodney W. Grimes*/ 95afe61c15SRodney W. Grimes 96afe61c15SRodney W. Grimesstruct dirent { 97afe61c15SRodney W. Grimes u_long d_fileno; /* file number of entry */ 98afe61c15SRodney W. Grimes u_short d_reclen; /* length of this record */ 99afe61c15SRodney W. Grimes u_short d_namlen; /* length of string in d_name */ 100afe61c15SRodney W. Grimes#ifdef _POSIX_SOURCE 101afe61c15SRodney W. Grimes char d_name[MAXNAMLEN + 1]; /* maximum name length */ 102afe61c15SRodney W. Grimes#else 103afe61c15SRodney W. Grimes#define MAXNAMLEN 255 104afe61c15SRodney W. Grimes char d_name[MAXNAMLEN + 1]; /* maximum name length */ 105afe61c15SRodney W. Grimes#endif 106afe61c15SRodney W. Grimes 107afe61c15SRodney W. Grimes}; 108afe61c15SRodney W. Grimes 109afe61c15SRodney W. Grimes#ifdef _POSIX_SOURCE 110afe61c15SRodney W. Grimestypedef void * DIR; 111afe61c15SRodney W. Grimes#else 112afe61c15SRodney W. Grimes 113afe61c15SRodney W. Grimes#define d_ino d_fileno /* backward compatibility */ 114afe61c15SRodney W. Grimes 115afe61c15SRodney W. Grimes/* definitions for library routines operating on directories. */ 116afe61c15SRodney W. Grimes#define DIRBLKSIZ 1024 117afe61c15SRodney W. Grimes 118afe61c15SRodney W. Grimes/* structure describing an open directory. */ 119afe61c15SRodney W. Grimestypedef struct _dirdesc { 120afe61c15SRodney W. Grimes int dd_fd; /* file descriptor associated with directory */ 121afe61c15SRodney W. Grimes long dd_loc; /* offset in current buffer */ 122afe61c15SRodney W. Grimes long dd_size; /* amount of data returned by getdirentries */ 123afe61c15SRodney W. Grimes char *dd_buf; /* data buffer */ 124afe61c15SRodney W. Grimes int dd_len; /* size of data buffer */ 125afe61c15SRodney W. Grimes long dd_seek; /* magic cookie returned by getdirentries */ 126afe61c15SRodney W. Grimes} DIR; 127afe61c15SRodney W. Grimes 128afe61c15SRodney W. Grimes#define dirfd(dirp) ((dirp)->dd_fd) 129afe61c15SRodney W. Grimes 130afe61c15SRodney W. Grimes#ifndef NULL 131afe61c15SRodney W. Grimes#define NULL 0 132afe61c15SRodney W. Grimes#endif 133afe61c15SRodney W. Grimes 134afe61c15SRodney W. Grimes#endif /* _POSIX_SOURCE */ 135afe61c15SRodney W. Grimes 136afe61c15SRodney W. Grimes#ifndef KERNEL 137afe61c15SRodney W. Grimes 138afe61c15SRodney W. Grimes#include <sys/cdefs.h> 139afe61c15SRodney W. Grimes 140afe61c15SRodney W. Grimes#endif /* !KERNEL */ 141afe61c15SRodney W. Grimes 142afe61c15SRodney W. Grimes#endif /* !_DIRENT_H_ */ 143afe61c15SRodney W. Grimes.Ed 144afe61c15SRodney W. Grimes.Sh SEE ALSO 145afe61c15SRodney W. Grimes.Xr fs 5 146afe61c15SRodney W. Grimes.Xr inode 5 147afe61c15SRodney W. Grimes.Sh HISTORY 148afe61c15SRodney W. GrimesA 149afe61c15SRodney W. Grimes.Nm 150afe61c15SRodney W. Grimesfile format appeared in 151afe61c15SRodney W. Grimes.At v7 . 152