home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 202.img / SCO386N2.TD0 / usr / include / sys / ndir.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-18  |  2.9 KB  |  84 lines

  1. /*
  2.  *    @(#) ndir.h 2.3 88/05/18 
  3.  *
  4.  *    Copyright (C) The Santa Cruz Operation, 1984, 1985, 1986, 1987, 1988.
  5.  *    Copyright (C) Microsoft Corporation, 1984, 1985, 1986, 1987, 1988.
  6.  *    This Module contains Proprietary Information of
  7.  *    The Santa Cruz Operation, Microsoft Corporation
  8.  *    and AT&T, and should be treated as Confidential.
  9.  */
  10.  
  11. /*
  12.  * Change notice (rti!trt):  To be compatible with non-bsd systems:
  13.  * #defines for u_short, u_long, and void added.
  14.  */
  15.  
  16. #define    u_short    unsigned short
  17. #define    u_long    long
  18.  
  19. /*
  20.  * A directory consists of some number of blocks of DIRBLKSIZ
  21.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  22.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  23.  *
  24.  * Each DIRBLKSIZ byte block contains some number of directory entry
  25.  * structures, which are of variable length.  Each directory entry has
  26.  * a struct direct at the front of it, containing its inode number,
  27.  * the length of the entry, and the length of the name contained in
  28.  * the entry.  These are followed by the name padded to a 4 byte boundary
  29.  * with null bytes.  All names are guaranteed null terminated.
  30.  * The maximum length of a name in a directory is MAXNAMLEN.
  31.  *
  32.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  33.  * a directory entry.  Free space in a directory is represented by
  34.  * entries which have dp->d_reclen >= DIRSIZ(dp).  All DIRBLKSIZ bytes
  35.  * in a directory block are claimed by the directory entries.  This
  36.  * usually results in the last entry in a directory having a large
  37.  * dp->d_reclen.  When entries are deleted from a directory, the
  38.  * space is returned to the previous entry in the same directory
  39.  * block by increasing its dp->d_reclen.  If the first entry of
  40.  * a directory block is free, then its dp->d_ino is set to 0.
  41.  * Entries other than the first in a directory do not normally have
  42.  * dp->d_ino set to 0.
  43.  */
  44. #define DIRBLKSIZ    512
  45. #define    MAXNAMLEN    255
  46.  
  47. struct    direct {
  48.     u_long    d_ino;            /* inode number of entry */
  49.     u_short    d_reclen;        /* length of this record */
  50.     u_short    d_namlen;        /* length of string in d_name */
  51.     char    d_name[MAXNAMLEN + 1];    /* name must be no longer than this */
  52. };
  53.  
  54. /*
  55.  * The DIRSIZ macro gives the minimum record length which will hold
  56.  * the directory entry.  This requires the amount of space in struct direct
  57.  * without the d_name field, plus enough space for the name with a terminating
  58.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  59.  */
  60. #undef DIRSIZ
  61. #define DIRSIZ(dp) \
  62.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  63.  
  64. #ifndef KERNEL
  65. /*
  66.  * Definitions for library routines operating on directories.
  67.  */
  68. typedef struct _dirdesc {
  69.     int    dd_fd;
  70.     long    dd_loc;
  71.     long    dd_size;
  72.     char    dd_buf[DIRBLKSIZ];
  73. } DIR;
  74. #ifndef NULL
  75. #define NULL 0
  76. #endif
  77. extern    DIR *opendir();
  78. extern    struct direct *readdir();
  79. extern    long telldir();
  80. extern    void seekdir();
  81. #define rewinddir(dirp)    seekdir((dirp), (long)0)
  82. extern    closedir();
  83. #endif /* KERNEL */
  84.