home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / dir.h < prev    next >
C/C++ Source or Header  |  1993-10-19  |  7KB  |  237 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  *
  7.  * HISTORY
  8.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  9.  *    Integrated POSIX changes
  10.  *
  11.  * 27-Sep-89  Morris Meyer (mmeyer) at NeXT
  12.  *    NFS 4.0 Changes.
  13.  *
  14.  * 13-Feb-88  John Seamons (jks) at NeXT
  15.  *    NeXT: increased DEV_BSIZE from 512 to 1024.
  16.  *
  17.  * 06-Jan-88  Jay Kistler (jjk) at Carnegie Mellon University
  18.  *    Added declarations for __STDC__.
  19.  *
  20.  * 10-Aug-87  Peter King (king) at NeXT
  21.  *    SUN_VFS:  Change d_ino to d_fileno.  Add dd_bbase, dd_entno, dd_bsize,
  22.  *          and dd_buf fields.
  23.  *
  24.  * 24-Jul-86  Michael Young (mwyoung) at Carnegie-Mellon University
  25.  *    Prevent repeated inclusion.
  26.  *
  27.  */
  28.  
  29. /*
  30.  * Copyright (c) 1982, 1986 Regents of the University of California.
  31.  * All rights reserved.  The Berkeley software License Agreement
  32.  * specifies the terms and conditions for redistribution.
  33.  *
  34.  *    @(#)dir.h    7.1 (Berkeley) 6/4/86
  35.  */
  36.  
  37. /* @(#)dir.h    1.4 87/06/02 3.2/4.3NFSSRC */
  38.  
  39. #ifndef    _DIR_
  40.     #define    _DIR_    1
  41.  
  42.     #if !defined(KERNEL) && defined(_POSIX_SOURCE)
  43.         #include <standards.h>
  44.     #endif
  45.     #import <sys/types.h>
  46.  
  47. /* SUN_VFS */
  48. /*
  49.  
  50.  * Filesystem-independent directory information.
  51.  * Directory entry structures are of variable length.
  52.  * Each directory entry is a struct direct containing its file number,
  53.  * the offset of the next entry (a cookie interpretable only the
  54.  * filesystem type that generated it), the length of the entry, and
  55.  * the length of the name contained in the entry.  These are followed
  56.  * by the name. The entire entry is padded with null bytes to a 4 byte
  57.  * boundary. All names are guaranteed null terminated. The maximum
  58.  * length of a name in a directory is MAXNAMLEN, plus a null byte.
  59.  * Note: SVID style filesystem-independant directory routines are
  60.  * supported by the files /usr/include/dirent.h and
  61.  * /usr/include/sys/dirent.h.
  62.  */
  63. /* else SUN_VFS */
  64. /*
  65.  * A directory consists of some number of blocks of DIRBLKSIZ
  66.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  67.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  68.  *
  69.  * Each DIRBLKSIZ byte block contains some number of directory entry
  70.  * structures, which are of variable length.  Each directory entry has
  71.  * a struct direct at the front of it, containing its inode number,
  72.  * the length of the entry, and the length of the name contained in
  73.  * the entry.  These are followed by the name padded to a 4 byte boundary
  74.  * with null bytes.  All names are guaranteed null terminated.
  75.  * The maximum length of a name in a directory is MAXNAMLEN.
  76.  *
  77.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  78.  * a directory entry.  Free space in a directory is represented by
  79.  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  80.  * in a directory block are claimed by the directory entries.  This
  81.  * usually results in the last entry in a directory having a large
  82.  * dp->d_reclen.  When entries are deleted from a directory, the
  83.  * space is returned to the previous entry in the same directory
  84.  * block by increasing its dp->d_reclen.  If the first entry of
  85.  * a directory block is free, then its dp->d_ino is set to 0.
  86.  * Entries other than the first in a directory do not normally have
  87.  * dp->d_ino set to 0.
  88.  */
  89. /* end SUN_VFS */
  90. /* so user programs can just include dir.h */
  91. #if !defined(KERNEL) && !defined(DEV_BSIZE) && defined(_NEXT_SOURCE)
  92.     #if !NeXT
  93.         #define    DEV_BSIZE    512
  94.     #endif    /* NeXT */
  95. #endif    /* !KERNEL && !DEV_BSIZE && _NEXT_SOURCE */
  96.  
  97. #ifdef _NEXT_SOURCE
  98.     #if NeXT
  99.         #define DIRBLKSIZ    1024
  100.     #else
  101.         #define DIRBLKSIZ    DEV_BSIZE
  102.     #endif    /* NeXT */
  103. #endif /* _NEXT_SOURCE */
  104.  
  105. #ifdef _NEXT_SOURCE
  106.  
  107.     #ifndef _MAXNAMLEN
  108.         #define _MAXNAMLEN
  109.         #define    MAXNAMLEN    255
  110.     #endif  /* _MAXNAMLEN */
  111.  
  112.     struct    direct {
  113.     /* SUN_VFS */
  114.         u_long  d_fileno;               /* file number of */
  115.                             /* entry */
  116.     /* SUN_VFS */
  117.     /*    u_long d_ino; */        /* inode number of */
  118.                         /* entry SUN_VFS */
  119.         u_short    d_reclen;        /* length of this */
  120.                         /* record */
  121.         u_short    d_namlen;        /* length of string */
  122.                         /* in d_name */
  123.         char    d_name[MAXNAMLEN + 1];    /* name must be no */
  124.                         /* longer than this */
  125.     };
  126.  
  127.     /*
  128.      * The DIRSIZ macro gives the minimum record length which will
  129.      * hold the directory entry.  This requires the amount of space
  130.      * in struct direct without the d_name field, plus enough space
  131.      * for the name with a terminating null byte (dp->d_namlen+1),
  132.      * rounded up to a 4 byte boundary.
  133.      */
  134.     #undef DIRSIZ
  135.     #define DIRSIZ(dp) \
  136.         ((sizeof (struct direct) - (MAXNAMLEN+1)) + \
  137.         (((dp)->d_namlen+1 + 3) &~ 3))
  138. #endif     /* _NEXT_SOURCE */
  139.  
  140. #ifndef KERNEL
  141.     /* SUN_VFS */
  142.     #ifdef _NEXT_SOURCE
  143.         #define d_ino   d_fileno    /* compatability */
  144.     #endif /* _NEXT_SOURCE */
  145.     /* SUN_VFS */
  146.  
  147.     /*
  148.      * Definitions for library routines operating on directories.
  149.      */
  150.  
  151.     #if defined(_POSIX_SOURCE) || defined(_NEXT_SOURCE)
  152.         typedef struct _dirdesc {
  153.             int    dd_fd;
  154.             long    dd_loc;
  155.             long    dd_size;
  156.         /* SUN_VFS */
  157.             long    dd_bbase;
  158.             long    dd_entno;
  159.             long    dd_bsize;
  160.             char    *dd_buf;
  161.         /* SUN_VFS */
  162.         /*    char    dd_buf[DIRBLKSIZ]; SUN_VFS */
  163.         } DIR;
  164.     #endif  /* _POSIX_SOURCE || _NEXT_SOURCE */
  165.  
  166.     #ifdef _NEXT_SOURCE
  167.         #ifndef NULL
  168.             #define NULL ((void *)0)
  169.         #endif /* NULL */
  170.     #endif /* _NEXT_SOURCE */
  171.  
  172.  
  173.     #if defined(_POSIX_SOURCE) || defined(_NEXT_SOURCE)
  174.         #ifdef __STDC__
  175.             extern    DIR *opendir(const char *dirname);
  176.             #if defined(_POSIX_SOURCE)
  177.                 extern    struct dirent *readdir(DIR *dirp);
  178.                 extern    void rewinddir(DIR *dirp);
  179.             #else
  180.                 extern    struct direct *readdir(DIR *dirp);
  181.                 #define rewinddir(dirp)    \
  182.                     seekdir((dirp), (long)0)
  183.             #endif     /* _POSIX_SOURCE */
  184.             extern    int closedir(DIR *dirp);
  185.  
  186.             #ifdef _NEXT_SOURCE
  187.                 extern void seekdir(DIR *, long);
  188.                 extern long telldir(DIR *);
  189.                 extern int \
  190.                     scandir(const char *, \
  191.                         struct direct ***, \
  192.                         int (*)(), int (*)());
  193.                 extern int \
  194.                     alphasort (struct direct **, \
  195.                         struct direct **);
  196.             #endif /* _NEXT_SOURCE */
  197.         #else /* __STDC__ */
  198.             extern    DIR *opendir();
  199.             #if defined(_POSIX_SOURCE)
  200.                 extern    struct dirent *readdir();
  201.                 extern  void rewinddir();
  202.             #else
  203.                 extern    struct direct *readdir();
  204.                 #define rewinddir(dirp)    \
  205.                     seekdir((dirp), (long)0)
  206.             #endif  /* _POSIX_SOURCE */
  207.             extern    int closedir();
  208.  
  209.             #ifdef _NEXT_SOURCE
  210.                 extern    void seekdir();
  211.                 extern    long telldir();
  212.                 extern    int scandir();
  213.                 extern    int alphasort();
  214.             #endif /* _NEXT_SOURCE */
  215.         #endif /* __STDC__ */
  216.     #endif /* _POSIX_SOURCE || _NEXT_SOURCE */
  217. #endif /* !KERNEL */
  218.  
  219. #ifdef KERNEL
  220.     /*
  221.      * Template for manipulating directories.
  222.      * Should use struct direct's, but the name field
  223.      * is MAXNAMLEN - 1, and this just won't do.
  224.      */
  225.     struct dirtemplate {
  226.         u_long    dot_ino;
  227.         short    dot_reclen;
  228.         short    dot_namlen;
  229.         char    dot_name[4];    /* must be multiple of 4 */
  230.         u_long    dotdot_ino;
  231.         short    dotdot_reclen;
  232.         short    dotdot_namlen;
  233.         char    dotdot_name[4];    /* ditto */
  234.     };
  235. #endif /* KERNEL */
  236. #endif /* _DIR_ */
  237.