home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / sys / namei.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  7.6 KB  |  202 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    namei.h,v $
  29.  * Revision 2.1  92/04/21  17:16:10  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*
  36.  * Copyright (c) 1985, 1989, 1991 Regents of the University of California.
  37.  * All rights reserved.
  38.  *
  39.  * Redistribution and use in source and binary forms, with or without
  40.  * modification, are permitted provided that the following conditions
  41.  * are met:
  42.  * 1. Redistributions of source code must retain the above copyright
  43.  *    notice, this list of conditions and the following disclaimer.
  44.  * 2. Redistributions in binary form must reproduce the above copyright
  45.  *    notice, this list of conditions and the following disclaimer in the
  46.  *    documentation and/or other materials provided with the distribution.
  47.  * 3. All advertising materials mentioning features or use of this software
  48.  *    must display the following acknowledgement:
  49.  *    This product includes software developed by the University of
  50.  *    California, Berkeley and its contributors.
  51.  * 4. Neither the name of the University nor the names of its contributors
  52.  *    may be used to endorse or promote products derived from this software
  53.  *    without specific prior written permission.
  54.  *
  55.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  56.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  57.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  58.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  59.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  60.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  61.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  62.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  65.  * SUCH DAMAGE.
  66.  *
  67.  *    @(#)namei.h    7.15 (Berkeley) 5/15/91
  68.  */
  69.  
  70. #ifndef _NAMEI_H_
  71. #define    _NAMEI_H_
  72.  
  73. /*
  74.  * Encapsulation of namei parameters.
  75.  */
  76. struct nameidata {
  77.     /*
  78.      * Arguments to namei.
  79.      */
  80.     caddr_t    ni_dirp;        /* pathname pointer */
  81.     enum    uio_seg ni_segflg;    /* location of pathname */
  82.     u_long    ni_nameiop;        /* see below */
  83.     /*
  84.      * Arguments to lookup.
  85.      */
  86.     struct    ucred *ni_cred;        /* credentials */
  87.     struct    vnode *ni_startdir;    /* starting directory */
  88.     struct    vnode *ni_rootdir;    /* logical root directory */
  89.     /*
  90.      * Results
  91.      */
  92.     struct    vnode *ni_vp;        /* vnode of result */
  93.     struct    vnode *ni_dvp;        /* vnode of intermediate directory */
  94.     /*
  95.      * Shared between namei, lookup routines, and commit routines.
  96.      */
  97.     char    *ni_pnbuf;        /* pathname buffer */
  98.     long    ni_pathlen;        /* remaining chars in path */
  99.     char    *ni_ptr;        /* current location in pathname */
  100.     long    ni_namelen;        /* length of current component */
  101.     char    *ni_next;        /* next location in pathname */
  102.     u_long    ni_hash;        /* hash value of current component */
  103.     u_char    ni_loopcnt;        /* count of symlinks encountered */
  104.     u_char    ni_makeentry;        /* 1 => add entry to name cache */
  105.     u_char    ni_isdotdot;        /* 1 => current component name is .. */
  106.     u_char    ni_more;        /* 1 => symlink needs interpretation */
  107.     /*
  108.      * Side effects.
  109.      */
  110.     struct ufs_specific {        /* saved info for new dir entry */
  111.         off_t    ufs_endoff;    /* end of useful directory contents */
  112.         long    ufs_offset;    /* offset of free space in directory */
  113.         long    ufs_count;    /* size of free slot in directory */
  114.         ino_t    ufs_ino;    /* inode number of found directory */
  115.         u_long    ufs_reclen;    /* size of found directory entry */
  116.     } ni_ufs;
  117. };
  118.  
  119. #ifdef KERNEL
  120. /*
  121.  * namei operations
  122.  */
  123. #define    LOOKUP        0    /* perform name lookup only */
  124. #define    CREATE        1    /* setup for file creation */
  125. #define    DELETE        2    /* setup for file deletion */
  126. #define    RENAME        3    /* setup for file renaming */
  127. #define    OPMASK        3    /* mask for operation */
  128. /*
  129.  * namei operational modifiers
  130.  */
  131. #define    LOCKLEAF    0x0004    /* lock inode on return */
  132. #define    LOCKPARENT    0x0008    /* want parent vnode returned locked */
  133. #define    WANTPARENT    0x0010    /* want parent vnode returned unlocked */
  134. #define    NOCACHE        0x0020    /* name must not be left in cache */
  135. #define    FOLLOW        0x0040    /* follow symbolic links */
  136. #define    NOFOLLOW    0x0000    /* do not follow symbolic links (pseudo) */
  137. #define    MODMASK        0x00fc    /* mask of operational modifiers */
  138. /*
  139.  * Namei parameter descriptors.
  140.  *
  141.  * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
  142.  * If the caller of namei sets the flag (for example execve wants to
  143.  * know the name of the program that is being executed), then it must
  144.  * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
  145.  * be freed by either the commit routine or the VOP_ABORT routine.
  146.  * SAVESTART is set only by the callers of namei. It implies SAVENAME
  147.  * plus the addition of saving the parent directory that contains the
  148.  * name in ni_startdir. It allows repeated calls to lookup for the
  149.  * name being sought. The caller is responsible for releasing the
  150.  * buffer and for vrele'ing ni_startdir.
  151.  */
  152. #define    NOCROSSMOUNT    0x0100    /* do not cross mount points */
  153. #define    REMOTE        0x0200    /* lookup for remote filesystem servers */
  154. #define    HASBUF        0x0400    /* has allocated pathname buffer */
  155. #define    SAVENAME    0x0800    /* save pathanme buffer */
  156. #define    SAVESTART    0x1000    /* save starting directory */
  157. #define PARAMASK    0xff00    /* mask of parameter descriptors */
  158. #endif
  159.  
  160. /*
  161.  * This structure describes the elements in the cache of recent
  162.  * names looked up by namei. NCHNAMLEN is sized to make structure
  163.  * size a power of two to optimize malloc's. Minimum reasonable
  164.  * size is 15.
  165.  */
  166.  
  167. #define    NCHNAMLEN    31    /* maximum name segment length we bother with */
  168.  
  169. struct    namecache {
  170.     struct    namecache *nc_forw;    /* hash chain, MUST BE FIRST */
  171.     struct    namecache *nc_back;    /* hash chain, MUST BE FIRST */
  172.     struct    namecache *nc_nxt;    /* LRU chain */
  173.     struct    namecache **nc_prev;    /* LRU chain */
  174.     struct    vnode *nc_dvp;        /* vnode of parent of name */
  175.     u_long    nc_dvpid;        /* capability number of nc_dvp */
  176.     struct    vnode *nc_vp;        /* vnode the name refers to */
  177.     u_long    nc_vpid;        /* capability number of nc_vp */
  178.     char    nc_nlen;        /* length of name */
  179.     char    nc_name[NCHNAMLEN];    /* segment name */
  180. };
  181.  
  182. #ifdef KERNEL
  183. u_long    nextvnodeid;
  184. int    namei __P((struct nameidata *ndp, struct proc *p));
  185. int    lookup __P((struct nameidata *ndp, struct proc *p));
  186. #endif
  187.  
  188. /*
  189.  * Stats on usefulness of namei caches.
  190.  */
  191. struct    nchstats {
  192.     long    ncs_goodhits;        /* hits that we can really use */
  193.     long    ncs_neghits;        /* negative hits that we can use */
  194.     long    ncs_badhits;        /* hits we must drop */
  195.     long    ncs_falsehits;        /* hits with id mismatch */
  196.     long    ncs_miss;        /* misses */
  197.     long    ncs_long;        /* long names that ignore cache */
  198.     long    ncs_pass2;        /* names found with passes == 2 */
  199.     long    ncs_2passes;        /* number of times we attempt it */
  200. };
  201. #endif /* !_NAMEI_H_ */
  202.