1: /*
   2:  * Copyright (c) 1982, 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)dir.h	7.1 (Berkeley) 6/4/86
   7:  */
   8: 
   9: /*
  10:  * A directory consists of some number of blocks of DIRBLKSIZ
  11:  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  12:  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  13:  *
  14:  * Each DIRBLKSIZ byte block contains some number of directory entry
  15:  * structures, which are of variable length.  Each directory entry has
  16:  * a struct direct at the front of it, containing its inode number,
  17:  * the length of the entry, and the length of the name contained in
  18:  * the entry.  These are followed by the name padded to a 4 byte boundary
  19:  * with null bytes.  All names are guaranteed null terminated.
  20:  * The maximum length of a name in a directory is MAXNAMLEN.
  21:  *
  22:  * The macro DIRSIZ(dp) gives the amount of space required to represent
  23:  * a directory entry.  Free space in a directory is represented by
  24:  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  25:  * in a directory block are claimed by the directory entries.  This
  26:  * usually results in the last entry in a directory having a large
  27:  * dp->d_reclen.  When entries are deleted from a directory, the
  28:  * space is returned to the previous entry in the same directory
  29:  * block by increasing its dp->d_reclen.  If the first entry of
  30:  * a directory block is free, then its dp->d_ino is set to 0.
  31:  * Entries other than the first in a directory do not normally have
  32:  * dp->d_ino set to 0.
  33:  */
  34: /* so user programs can just include dir.h */
  35: #if !defined(KERNEL) && !defined(DEV_BSIZE)
  36: #define DEV_BSIZE   512
  37: #endif
  38: #define DIRBLKSIZ   DEV_BSIZE
  39: #define MAXNAMLEN   255
  40: 
  41: struct  direct {
  42:     u_long  d_ino;          /* inode number of entry */
  43:     u_short d_reclen;       /* length of this record */
  44:     u_short d_namlen;       /* length of string in d_name */
  45:     char    d_name[MAXNAMLEN + 1];  /* name must be no longer than this */
  46: };
  47: 
  48: /*
  49:  * The DIRSIZ macro gives the minimum record length which will hold
  50:  * the directory entry.  This requires the amount of space in struct direct
  51:  * without the d_name field, plus enough space for the name with a terminating
  52:  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  53:  */
  54: #undef DIRSIZ
  55: #define DIRSIZ(dp) \
  56:     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  57: 
  58: #ifndef KERNEL
  59: /*
  60:  * Definitions for library routines operating on directories.
  61:  */
  62: typedef struct _dirdesc {
  63:     int dd_fd;
  64:     long    dd_loc;
  65:     long    dd_size;
  66:     char    dd_buf[DIRBLKSIZ];
  67: } DIR;
  68: #ifndef NULL
  69: #define NULL 0
  70: #endif
  71: extern  DIR *opendir();
  72: extern  struct direct *readdir();
  73: extern  long telldir();
  74: extern  void seekdir();
  75: #define rewinddir(dirp) seekdir((dirp), (long)0)
  76: extern  void closedir();
  77: #endif
  78: 
  79: #ifdef KERNEL
  80: /*
  81:  * Template for manipulating directories.
  82:  * Should use struct direct's, but the name field
  83:  * is MAXNAMLEN - 1, and this just won't do.
  84:  */
  85: struct dirtemplate {
  86:     u_long  dot_ino;
  87:     short   dot_reclen;
  88:     short   dot_namlen;
  89:     char    dot_name[4];        /* must be multiple of 4 */
  90:     u_long  dotdot_ino;
  91:     short   dotdot_reclen;
  92:     short   dotdot_namlen;
  93:     char    dotdot_name[4];     /* ditto */
  94: };
  95: #endif

Defined struct's

_dirdesc defined in line 62; never used
direct defined in line 41; used 36 times
dirtemplate defined in line 85; used 16 times

Defined typedef's

DIR defined in line 67; used 1 times
  • in line 71

Defined macros

DIRBLKSIZ defined in line 38; used 18 times
DIRSIZ defined in line 55; used 12 times
MAXNAMLEN defined in line 39; used 4 times
NULL defined in line 69; used 389 times
rewinddir defined in line 75; never used

Usage of this include

dir.h used 113 times
Last modified: 1986-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1043
Valid CSS Valid XHTML 1.0 Strict