Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ dir(5) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

read, readv, readx

ulimit

fs

inode



DIR(5,F)                    AIX Technical Reference                    DIR(5,F)



-------------------------------------------------------------------------------
dir



PURPOSE

Describes the format of a directory.

SYNOPSIS

#include <sys/types.h>
#include <dirent.h>

DESCRIPTION

A directory is a file that a user is not allowed to write into directly.  A
directory file contains a variable-sized entry for each file in it.  A bit in
the file mode of the inode entry indicates that the corresponding file should
be treated as a directory.  For additional information about a system volume
format, see "fs" and "inode."

The recommended way for a program to read a directory is through readdir (see
"directory: opendir, readdir, telldir, seekdir, rewinddir, closedir") or readx
(see "read, readv, readx").  If a program uses read, and that process hasn't
been marked with the "real directory read" attribute (see "ulimit"), the system
will presume that the program is expecting fixed-sized directory entries.  See
System V compatibility, described below.

A directory consists of some number of blocks of DIRBLKSIZ bytes (defined in
<dirent.h>), or exactly one block of size SMBLKSZ bytes (defined in
<sys/ino.h>).  Each directory block contains some number of directory entry
structures, which are of variable length.  Each 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 16-byte boundary with null bytes.  All names are
guaranteed null-terminated.  The maximum length of a name in a directory is
NAME_MAX.  The maximum length of an entire path name is PATH_MAX.  Neither
NAME_MAX nor PATH_MAX includes the terminating null character.

The macro "NDIRSIZ(dp)" gives the amount of space required to represent a
directory entry.  Free space in a directory is represented by entries that have
  "dp->d_reclen > DIRSIZ(dp)".  All DIRBLKSIZ (or SMBLKSZ) bytes in a directory
block are claimed by the directory entries.  This usually results in the last
entry in a directory having a large   "dp->d_reclen".  When entries are deleted
from a directory, the space is returned to the previous entry in the same
directory block by increasing its   "dp->d_reclen".  If the first entry of a
directory block is freed, then its   "dp->d_ino" is set to 0.  Entries other
than the first in a directory block do not normally have   "dp->d_ino" set to
0.





Processed November 7, 1990         DIR(5,F)                                   1





DIR(5,F)                    AIX Technical Reference                    DIR(5,F)



  struct  dirent  {
          ino_t      d_ino;
          u_short      d_reclen;
          u_short      d_namlen;
          char          d_name[NAME_MAX  + 1];
          /* typically shorter */
  };

  #define NDIRSIZ(dp) \
     (((sizeof(struct dirent) - (NAME_MAX+1)) + ((dp)->d_namlen+1 + 15)) &^ 15)

By convention, the first two entries in each directory are for . (dot) and ..
(dot dot).  The first . is an entry for the directory itself.  The .. entry is
for the parent directory.  The meaning of the .. entry for the root directory
of the master file system is modified.  There is no parent directory;
therefore, the .. entry has the same meaning as the . entry.

Compatibility Interfaces

For compatibility with UNIX System V and earlier AIX systems, which employed
fixed-sized 16-byte directory entries, the direct structure has been preserved.
This is the structure returned by programs which call the read system call
directly:

  #define  DIRSIZ  14
  struct   direct
  {
           s_ino_t  d_ino;
           char     d_name[DIRSIZ];
  };

For compatibility with 4.3BSD, which uses struct direct and DIRSIZ to describe
the variable-sized directory entries, the following definitions are made.  One
must define _BSD in a program to get these 4.3BSD definitions.

  #ifdef _BSD
  #define direct dirent
  #define DIRSIZ(dp) NDIRSIZ(dp)
  #endif

RELATED INFORMATION

In this book:  "read, readv, readx," "ulimit," "fs," and "inode."












Processed November 7, 1990         DIR(5,F)                                   2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026