home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / bsd / ufs / fsdir.h < prev    next >
Text File  |  1992-07-29  |  3KB  |  80 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software LiceUD5Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  **********************************************************************
  7.  * HISTORY
  8.  * 24-Jan-89  Peter King (king) at NeXT
  9.  *    NFS 4.0 Changes.  Cleaned out old directory cruft.
  10.  *
  11.  **********************************************************************
  12.  */
  13.  
  14. /* 
  15.  * Copyright (c) 1988 by Sun Microsystems, Inc.
  16.  * @(#) from SUN 2.6; from UCB 4.5 82/11/13
  17.  */
  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    1024        /* a convenient number */
  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 terminatinUD6 null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  58.  */
  59. #undef DIRSIZ
  60. #define DIRSIZ(dp) \
  61.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  62.  
  63. #ifdef KERNEL
  64. /*
  65.  * Template for manipulating directories.
  66.  * Should use struct direct's, but the name field
  67.  * is MAXNAMLEN - 1, and this just won't do.
  68.  */
  69. struct dirtemplate {
  70.     u_long    dot_ino;
  71.     short    dot_reclen;
  72.     short    dot_namlen;
  73.     char    dot_name[4];        /* must be multiple of 4 */
  74.     u_long    dotdot_ino;
  75.     short    dotdot_reclen;
  76.     short    dotdot_namlen;
  77.     char    dotdot_name[4];        /* ditto */
  78. };
  79. #endif
  80.