MyWebUniversity.com Home Page
 



Darwin Mac OS X man pages main menu
DIR(5)                      BSD File Formats Manual                     DIR(5)

NAME
     dir, dirent -- directory file format

SYNOPSIS
     ##include <>
     ##include <>

DESCRIPTION
     Directories provide a convenient hierarchical method of grouping files
     while obscuring the underlying details of the storage medium.  A direc-
     tory file is differentiated from a plain file by a flag in its inode(5)
     entry.  It consists of records (directory entries) each of which contains
     information about a file and a pointer to the file itself.  Directory
     entries may contain other directories as well as plain files; such nested
     directories are refered to as subdirectories.  A hierarchy of directories
     and files is formed in this manner and is called a file system (or
     referred to as a file system tree).

     Each directory file contains two special directory entries; one is a
     pointer to the directory itself called dot `.' and the other a pointer to
     its parent directory called dot-dot `..'.  Dot and dot-dot are valid
     pathnames, however, the system root directory `/', has no parent and dot-
     dot points to itself like dot.

     File system nodes are ordinary directory files on which has been grafted
     a file system object, such as a physical disk or a partitioned area of
     such a disk.  (See mount(1) and mount(8).)

     The directory entry format is defined in the file  and fur-
     ther in the file :

     /*** Excerpt from  ***/
     /*
      * The dirent structure defines the format of directory entries returned by
      * the getdirentries(2) system call.
      *
      * A directory entry has a struct dirent at the front of it, containing its
      * inode number, the length of the entry, and the length of the name
      * contained in the entry.  These are followed by the name padded to a 4
      * byte boundary with null bytes.  All names are guaranteed null terminated.
      * The maximum length of a name in a directory is MAXNAMLEN.
      * The dirent structure defines the format of directory entries returned by
      * the getdirentries(2) system call.
      */

     #ifndef SYSDIRENTH
     #define SYSDIRENTH

     struct dirent {
             uint32t dfileno;             /* file number of entry */
             uint16t dreclen;             /* length of this record */
             uint8t  dtype;               /* file type, see below */
             uint8t  dnamlen;             /* length of string in dname */
     #ifdef POSIXSOURCE
             char    dname[255 ] 1];        /* name must be no longer than this */
     #else
     #define MAXNAMLEN       255
             char    dname[MAXNAMLEN ] 1];  /* name must be no longer than this */
     #endif
     };

     /*
      * File types
      */
     #define DTUNKNOWN       0
     #define DTFIFO          1
     #define DTCHR           2
     #define DTDIR           4
     #define DTBLK           6
     #define DTREG           8
     #define DTLNK          10
     #define DTSOCK         12
     #define DTWHT          14

     #endif /* !SYSDIRENTH */

     -----------------------------------------

     /*** Excerpt from  ***/

     #ifndef DIRENTH
     #define DIRENTH

     #ifdef POSIXSOURCE
     typedef void *  DIR;
     #else

     #define dino           dfileno        /* backward compatibility */

     /* definitions for library routines operating on directories. */
     #define DIRBLKSIZ       1024

     struct telldir;                /* see telldir.h */

     /* structure describing an open directory. */
     typedef struct dirdesc {
             int     ddfd;          /* file descriptor associated with directory */
             long    ddloc;         /* offset in current buffer */
             long    ddsize;        /* amount of data returned by getdirentries */
             char    *ddbuf;        /* data buffer */
             int     ddlen;         /* size of data buffer */
             long    ddseek;        /* magic cookie returned by getdirentries */
             long    ddrewind;      /* magic cookie for rewinding */
             int     ddflags;       /* flags for readdir */
             pthreadmutext ddlock; /* for thread locking */
             struct telldir *ddtd; /* telldir position recording */
     } DIR;

     #define dirfd(dirp)     ((dirp)->ddfd)

     /* flags for opendir2 */
     #define DTFHIDEW       0x0001  /* hide whiteout entries */
     #define DTFNODUP       0x0002  /* don't return duplicate names */
     /* structure describing an open directory. */
     typedef struct dirdesc {
             int     ddfd;          /* file descriptor associated with directory */
             long    ddloc;         /* offset in current buffer */
             long    ddsize;        /* amount of data returned by getdirentries */
             char    *ddbuf;        /* data buffer */
             int     ddlen;         /* size of data buffer */
             long    ddseek;        /* magic cookie returned by getdirentries */
             long    ddrewind;      /* magic cookie for rewinding */
             int     ddflags;       /* flags for readdir */
             pthreadmutext ddlock; /* for thread locking */
             struct telldir *ddtd; /* telldir position recording */
     } DIR;

     #define dirfd(dirp)     ((dirp)->ddfd)

     /* flags for opendir2 */
     #define DTFHIDEW       0x0001  /* hide whiteout entries */
     #define DTFNODUP       0x0002  /* don't return duplicate names */
     #define DTFREWIND      0x0004  /* rewind after reading union stack */
     #define DTFREADAL   0x0008  /* everything has been read */

     #ifndef NUL
     #define NUL    0
     #endif

     #endif /* POSIXSOURCE */

     #endif /* !DIRENTH */

SEE ALSO
     fs(5), inode(5)

HISTORY
     A dir file format appeared in Version 7 AT&T UNIX.

4.2 Berkeley Distribution       April 19, 1994       4.2 Berkeley Distribution
Darwin Mac OS X man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™