The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/namei.src

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: namei.src,v 1.8.14.2 2010/02/14 13:27:45 bouyer Exp $  */
    2 
    3 /*
    4  * Copyright (c) 1985, 1989, 1991, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)namei.h     8.5 (Berkeley) 8/20/94
   32  */
   33 
   34 #ifndef _SYS_NAMEI_H_
   35 #define _SYS_NAMEI_H_
   36 
   37 #include <sys/queue.h>
   38 #include <sys/mutex.h>
   39 
   40 #ifdef _KERNEL
   41 #include <sys/kauth.h>
   42 
   43 /*
   44  * Encapsulation of namei parameters.
   45  */
   46 struct nameidata {
   47         /*
   48          * Arguments to namei/lookup.
   49          */
   50         const char *ni_dirp;            /* pathname pointer */
   51         enum    uio_seg ni_segflg;      /* location of pathname */
   52         /*
   53          * Arguments to lookup.
   54          */
   55         struct  vnode *ni_startdir;     /* starting directory */
   56         struct  vnode *ni_rootdir;      /* logical root directory */
   57         struct  vnode *ni_erootdir;     /* emulation root directory */
   58         /*
   59          * Results: returned from/manipulated by lookup
   60          */
   61         struct  vnode *ni_vp;           /* vnode of result */
   62         struct  vnode *ni_dvp;          /* vnode of intermediate directory */
   63         /*
   64          * Shared between namei and lookup/commit routines.
   65          */
   66         size_t          ni_pathlen;     /* remaining chars in path */
   67         const char      *ni_next;       /* next location in pathname */
   68         unsigned int    ni_loopcnt;     /* count of symlinks encountered */
   69         /*
   70          * Lookup parameters: this structure describes the subset of
   71          * information from the nameidata structure that is passed
   72          * through the VOP interface.
   73          */
   74         struct componentname {
   75                 /*
   76                  * Arguments to lookup.
   77                  */
   78                 uint32_t        cn_nameiop;     /* namei operation */
   79                 uint32_t        cn_flags;       /* flags to namei */
   80                 kauth_cred_t    cn_cred;        /* credentials */
   81                 /*
   82                  * Shared between lookup and commit routines.
   83                  */
   84                 char            *cn_pnbuf;      /* pathname buffer */
   85                 const char      *cn_nameptr;    /* pointer to looked up name */
   86                 size_t          cn_namelen;     /* length of looked up comp */
   87                 u_long          cn_hash;        /* hash val of looked up name */
   88                 size_t          cn_consume;     /* chars to consume in lookup */
   89         } ni_cnd;
   90 };
   91 
   92 /*
   93  * namei operations
   94  */
   95 NAMEIFL LOOKUP          0       /* perform name lookup only */
   96 NAMEIFL CREATE          1       /* setup for file creation */
   97 NAMEIFL DELETE          2       /* setup for file deletion */
   98 NAMEIFL RENAME          3       /* setup for file renaming */
   99 NAMEIFL OPMASK          3       /* mask for operation */
  100 /*
  101  * namei operational modifier flags, stored in ni_cnd.cn_flags
  102  */
  103 NAMEIFL LOCKLEAF        0x0004  /* lock inode on return */
  104 NAMEIFL LOCKPARENT      0x0008  /* want parent vnode returned locked */
  105 NAMEIFL NOCHROOT        0x0010  /* no chroot on abs path lookups */
  106 NAMEIFL NOCACHE         0x0020  /* name must not be left in cache */
  107 NAMEIFL FOLLOW          0x0040  /* follow symbolic links */
  108 NAMEIFL NOFOLLOW        0x0000  /* do not follow symbolic links (pseudo) */
  109 NAMEIFL TRYEMULROOT     0x0010  /* try relative to emulation root first */
  110 NAMEIFL EMULROOTSET     0x0080  /* emulation root already in ni_erootdir */
  111 NAMEIFL MODMASK         0x00fc  /* mask of operational modifiers */
  112 /*
  113  * Namei parameter descriptors.
  114  *
  115  * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
  116  * If the caller of namei sets the flag (for example execve wants to
  117  * know the name of the program that is being executed), then it must
  118  * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
  119  * be freed by either the commit routine or the VOP_ABORT routine.
  120  * SAVESTART is set only by the callers of namei. It implies SAVENAME
  121  * plus the addition of saving the parent directory that contains the
  122  * name in ni_startdir. It allows repeated calls to lookup for the
  123  * name being sought. The caller is responsible for releasing the
  124  * buffer and for vrele'ing ni_startdir.
  125  */
  126 NAMEIFL NOCROSSMOUNT    0x0000100       /* do not cross mount points */
  127 NAMEIFL RDONLY          0x0000200       /* lookup with read-only semantics */
  128 NAMEIFL HASBUF          0x0000400       /* has allocated pathname buffer */
  129 NAMEIFL SAVENAME        0x0000800       /* save pathname buffer */
  130 NAMEIFL SAVESTART       0x0001000       /* save starting directory */
  131 NAMEIFL ISDOTDOT        0x0002000       /* current component name is .. */
  132 NAMEIFL MAKEENTRY       0x0004000       /* entry is to be added to name cache */
  133 NAMEIFL ISLASTCN        0x0008000       /* this is last component of pathname */
  134 NAMEIFL ISSYMLINK       0x0010000       /* symlink needs interpretation */
  135 NAMEIFL ISWHITEOUT      0x0020000       /* found whiteout */
  136 NAMEIFL DOWHITEOUT      0x0040000       /* do whiteouts */
  137 NAMEIFL REQUIREDIR      0x0080000       /* must be a directory */
  138 NAMEIFL CREATEDIR       0x0200000       /* trailing slashes are ok */
  139 NAMEIFL INRENAME        0x0400000       /* operation is a part of ``rename'' */
  140 NAMEIFL PARAMASK        0x06fff00       /* mask of parameter descriptors */
  141 
  142 /*
  143  * Initialization of an nameidata structure.
  144  */
  145 #define NDINIT(ndp, op, flags, segflg, namep) { \
  146         (ndp)->ni_cnd.cn_nameiop = op; \
  147         (ndp)->ni_cnd.cn_flags = flags; \
  148         (ndp)->ni_segflg = segflg; \
  149         (ndp)->ni_dirp = namep; \
  150         (ndp)->ni_cnd.cn_cred = kauth_cred_get(); \
  151 }
  152 #endif
  153 
  154 /*
  155  * This structure describes the elements in the cache of recent
  156  * names looked up by namei. NCHNAMLEN is sized to make structure
  157  * size a power of two to optimize malloc's. Minimum reasonable
  158  * size is 15.
  159  */
  160 
  161 #define NCHNAMLEN       31      /* maximum name segment length we bother with */
  162 
  163 /*
  164  * Namecache entry.  This structure is arranged so that frequently
  165  * accessed and mostly read-only data is toward the front, with
  166  * infrequently accessed data and the lock towards the rear.  The
  167  * lock is then more likely to be in a seperate cache line.
  168  */
  169 struct  namecache {
  170         LIST_ENTRY(namecache) nc_hash;  /* hash chain */
  171         LIST_ENTRY(namecache) nc_vhash; /* directory hash chain */
  172         struct  vnode *nc_dvp;          /* vnode of parent of name */
  173         struct  vnode *nc_vp;           /* vnode the name refers to */
  174         int     nc_flags;               /* copy of componentname's ISWHITEOUT */
  175         char    nc_nlen;                /* length of name */
  176         char    nc_name[NCHNAMLEN];     /* segment name */
  177         void    *nc_gcqueue;            /* queue for garbage collection */
  178         TAILQ_ENTRY(namecache) nc_lru;  /* psuedo-lru chain */
  179         LIST_ENTRY(namecache) nc_dvlist;
  180         LIST_ENTRY(namecache) nc_vlist;
  181         kmutex_t nc_lock;               /* lock on this entry */
  182         int     nc_hittime;             /* last time scored a hit */
  183 };
  184 
  185 #ifdef _KERNEL
  186 #include <sys/mallocvar.h>
  187 #include <sys/pool.h>
  188 
  189 struct mount;
  190 struct cpu_info;
  191 
  192 extern pool_cache_t pnbuf_cache;        /* pathname buffer cache */
  193 
  194 #define PNBUF_GET()     pool_cache_get(pnbuf_cache, PR_WAITOK)
  195 #define PNBUF_PUT(pnb)  pool_cache_put(pnbuf_cache, (pnb))
  196 
  197 int     namei(struct nameidata *);
  198 uint32_t namei_hash(const char *, const char **);
  199 int     lookup(struct nameidata *);
  200 int     relookup(struct vnode *, struct vnode **, struct componentname *);
  201 void    cache_purge1(struct vnode *, const struct componentname *, int);
  202 #define PURGE_PARENTS   1
  203 #define PURGE_CHILDREN  2
  204 #define cache_purge(vp) cache_purge1((vp), NULL, PURGE_PARENTS|PURGE_CHILDREN)
  205 int     cache_lookup(struct vnode *, struct vnode **, struct componentname *);
  206 int     cache_lookup_raw(struct vnode *, struct vnode **,
  207                          struct componentname *);
  208 int     cache_revlookup(struct vnode *, struct vnode **, char **, char *);
  209 void    cache_enter(struct vnode *, struct vnode *, struct componentname *);
  210 void    nchinit(void);
  211 void    nchreinit(void);
  212 void    cache_cpu_init(struct cpu_info *);
  213 void    cache_purgevfs(struct mount *);
  214 void    namecache_print(struct vnode *, void (*)(const char *, ...));
  215 
  216 #endif
  217 
  218 /*
  219  * Stats on usefulness of namei caches.
  220  * XXX: should be 64-bit counters.
  221  */
  222 struct  nchstats {
  223         long    ncs_goodhits;           /* hits that we can really use */
  224         long    ncs_neghits;            /* negative hits that we can use */
  225         long    ncs_badhits;            /* hits we must drop */
  226         long    ncs_falsehits;          /* hits with id mismatch */
  227         long    ncs_miss;               /* misses */
  228         long    ncs_long;               /* long names that ignore cache */
  229         long    ncs_pass2;              /* names found with passes == 2 */
  230         long    ncs_2passes;            /* number of times we attempt it */
  231         long    ncs_revhits;            /* reverse-cache hits */
  232         long    ncs_revmiss;            /* reverse-cache misses */
  233 };
  234 
  235 #ifdef _KERNEL
  236 extern struct nchstats nchstats;
  237 #endif
  238 /* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */

Cache object: 840b5fc5d375957e0771986d115d0c06


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.