home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / lan / soss.arj / SRC / UDIR.H < prev   
C/C++ Source or Header  |  1991-02-22  |  3KB  |  85 lines

  1. /* @(#)udir.h    1.1 86/06/30 UNFSSRC */
  2.  
  3. /*
  4.  * Copyright (c) 1986 Sun Microsystems, Inc.
  5.  */
  6.  
  7. /*
  8.  * A directory consists of some number of blocks each of which is
  9.  * less than or equal to the filesystem block size number of
  10.  * bytes.
  11.  *
  12.  * Each block contains some number of directory entry structures,
  13.  * which are of variable length.  Each directory entry has
  14.  * a struct direct at the front of it, containing its file number,
  15.  * the length of the entry, and the length of the name contained in
  16.  * the entry.  These are followed by the name padded to a 4 byte boundary
  17.  * with null bytes.  All names are guaranteed null terminated.
  18.  * The maximum length of a name in a directory is MAXNAMLEN, plus
  19.  * a null byte.
  20.  *
  21.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  22.  * a directory entry.  Free space in a directory is represented by
  23.  * entries which have dp->d_reclen > DIRSIZ(dp).
  24.  *
  25.  * All the bytes in a directory block are claimed by the directory entries.
  26.  * This usually results in the last entry in a directory having a large
  27.  * dp->d_reclen.  Free entries have their dp->d_fileno set to 0.
  28.  */
  29. #define    MAXNAMLEN    255
  30.  
  31. struct    direct {
  32.     u_long    d_fileno;        /* file number of entry */
  33.     u_short    d_reclen;        /* length of this record */
  34.     u_short    d_namlen;        /* length of string in d_name */
  35.     char    d_name[MAXNAMLEN + 1];    /* name (up to MAXNAMLEN + 1) */
  36. };
  37.  
  38. /*
  39.  * user-level nfs cookie includes offset field.
  40.  */
  41. struct    udirect {
  42.     u_long    d_fileno;        /* file number of entry */
  43.     u_short    d_reclen;        /* length of this record */
  44.     u_short d_namlen;        /* length of string d_name */
  45.     u_long    d_offset;        /* offset into the directory */
  46.     char    d_name[MAXNAMLEN + 1];    /* name (up to MAXNAMLEN + 1) */
  47. };
  48.  
  49.  
  50. /*
  51.  * The DIRSIZ macro gives the minimum record length which will hold
  52.  * the directory entry.  This requires the amount of space in struct direct
  53.  * without the d_name field, plus enough space for the name with a terminating
  54.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  55.  */
  56. #undef DIRSIZ
  57. #define DIRSIZ(dp) \
  58.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  59.  
  60. #define UDIRSIZ(dp) \
  61.     ((sizeof (struct udirect) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  62.  
  63. /*
  64.  * Definitions for library routines operating on directories.
  65.  */
  66. typedef struct _dirdesc {
  67.     int    dd_fd;
  68.     long    dd_loc;
  69.     long    dd_size;
  70.     long    dd_bbase;
  71.     long    dd_entno;
  72.     long    dd_bsize;
  73.     char    *dd_buf;
  74. } DIR;
  75.  
  76. #ifndef NULL
  77. #define NULL 0
  78. #endif
  79. extern    DIR *opendir();
  80. extern    struct direct *readdir();
  81. extern    long telldir();
  82. extern    void seekdir();
  83. #define rewinddir(dirp)    seekdir((dirp), (long)0)
  84. extern    void closedir();
  85.