home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilss / sockets / include / sys / h / dir < prev    next >
Encoding:
Text File  |  1995-01-11  |  3.7 KB  |  119 lines

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