[BACK]Return to namei.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/namei.h, Revision 1.114

1.111     ad          1: /*     $NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp $    */
1.64      enami       2:
1.51      pooka       3:
                      4: /*
                      5:  * WARNING: GENERATED FILE.  DO NOT EDIT
1.64      enami       6:  * (edit namei.src and run make namei in src/sys/sys)
1.69      dholland    7:  *   by:   NetBSD: gennameih.awk,v 1.5 2009/12/23 14:17:19 pooka Exp
1.113     ad          8:  *   from: NetBSD: namei.src,v 1.58 2020/05/30 20:16:14 ad Exp
1.51      pooka       9:  */
1.6       cgd        10:
1.1       cgd        11: /*
1.4       mycroft    12:  * Copyright (c) 1985, 1989, 1991, 1993
                     13:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd        14:  *
                     15:  * Redistribution and use in source and binary forms, with or without
                     16:  * modification, are permitted provided that the following conditions
                     17:  * are met:
                     18:  * 1. Redistributions of source code must retain the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer.
                     20:  * 2. Redistributions in binary form must reproduce the above copyright
                     21:  *    notice, this list of conditions and the following disclaimer in the
                     22:  *    documentation and/or other materials provided with the distribution.
1.33      agc        23:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        24:  *    may be used to endorse or promote products derived from this software
                     25:  *    without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     28:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     29:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     30:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     31:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     32:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     33:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     34:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     35:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     36:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     37:  * SUCH DAMAGE.
                     38:  *
1.14      fvdl       39:  *     @(#)namei.h     8.5 (Berkeley) 8/20/94
1.1       cgd        40:  */
                     41:
1.2       mycroft    42: #ifndef _SYS_NAMEI_H_
1.4       mycroft    43: #define        _SYS_NAMEI_H_
1.1       cgd        44:
1.7       mycroft    45: #include <sys/queue.h>
1.59      ad         46: #include <sys/mutex.h>
1.60      ad         47:
1.110     christos   48: #if defined(_KERNEL) || defined(_MODULE)
1.59      ad         49: #include <sys/kauth.h>
1.105     ad         50: #include <sys/rwlock.h>
1.59      ad         51:
1.1       cgd        52: /*
1.69      dholland   53:  * Abstraction for a single pathname.
                     54:  *
                     55:  * This contains both the pathname string and (eventually) all
                     56:  * metadata that determines how the path is to be interpreted.
                     57:  * It is an opaque structure; the implementation is in vfs_lookup.c.
                     58:  *
                     59:  * To call namei, first set up a pathbuf with pathbuf_create or
                     60:  * pathbuf_copyin, then do NDINIT(), then call namei, then AFTER THE
                     61:  * STRUCT NAMEIDATA IS DEAD, call pathbuf_destroy. Don't destroy the
                     62:  * pathbuf before you've finished using the nameidata, or mysterious
                     63:  * bad things may happen.
1.70      dholland   64:  *
                     65:  * pathbuf_assimilate is like pathbuf_create but assumes ownership of
                     66:  * the string buffer passed in, which MUST BE of size PATH_MAX and
                     67:  * have been allocated with PNBUF_GET(). This should only be used when
                     68:  * absolutely necessary; e.g. nfsd uses it for loading paths from
                     69:  * mbufs.
1.69      dholland   70:  */
                     71: struct pathbuf;
                     72:
                     73: struct pathbuf *pathbuf_create(const char *path);
1.70      dholland   74: struct pathbuf *pathbuf_assimilate(char *path);
1.69      dholland   75: int pathbuf_copyin(const char *userpath, struct pathbuf **ret);
                     76: void pathbuf_destroy(struct pathbuf *);
                     77:
                     78: /* get a copy of the (current) path string */
                     79: void pathbuf_copystring(const struct pathbuf *, char *buf, size_t maxlen);
                     80:
                     81: /* hold a reference copy of the original path string */
                     82: const char *pathbuf_stringcopy_get(struct pathbuf *);
                     83: void pathbuf_stringcopy_put(struct pathbuf *, const char *);
                     84:
                     85: // XXX remove this
                     86: int pathbuf_maybe_copyin(const char *userpath, enum uio_seg seg, struct pathbuf **ret);
                     87:
                     88: /*
1.92      dennis     89:  * Lookup parameters: this structure describes the subset of
                     90:  * information from the nameidata structure that is passed
                     91:  * through the VOP interface.
                     92:  */
                     93: struct componentname {
                     94:        /*
                     95:         * Arguments to lookup.
                     96:         */
                     97:        uint32_t        cn_nameiop;     /* namei operation */
                     98:        uint32_t        cn_flags;       /* flags to namei */
                     99:        kauth_cred_t    cn_cred;        /* credentials */
                    100:        /*
                    101:         * Shared between lookup and commit routines.
                    102:         */
                    103:        const char      *cn_nameptr;    /* pointer to looked up name */
                    104:        size_t          cn_namelen;     /* length of looked up comp */
                    105:        size_t          cn_consume;     /* chars to consume in lookup */
                    106: };
                    107:
                    108: /*
1.1       cgd       109:  * Encapsulation of namei parameters.
                    110:  */
                    111: struct nameidata {
                    112:        /*
1.4       mycroft   113:         * Arguments to namei/lookup.
1.1       cgd       114:         */
1.85      dholland  115:        struct vnode *ni_atdir;         /* startup dir, cwd if null */
1.69      dholland  116:        struct pathbuf *ni_pathbuf;     /* pathname container */
1.70      dholland  117:        char *ni_pnbuf;                 /* extra pathname buffer ref (XXX) */
1.1       cgd       118:        /*
                    119:         * Arguments to lookup.
                    120:         */
                    121:        struct  vnode *ni_rootdir;      /* logical root directory */
1.49      dsl       122:        struct  vnode *ni_erootdir;     /* emulation root directory */
1.1       cgd       123:        /*
1.4       mycroft   124:         * Results: returned from/manipulated by lookup
1.1       cgd       125:         */
                    126:        struct  vnode *ni_vp;           /* vnode of result */
                    127:        struct  vnode *ni_dvp;          /* vnode of intermediate directory */
                    128:        /*
1.4       mycroft   129:         * Shared between namei and lookup/commit routines.
1.1       cgd       130:         */
1.53      pooka     131:        size_t          ni_pathlen;     /* remaining chars in path */
                    132:        const char      *ni_next;       /* next location in pathname */
                    133:        unsigned int    ni_loopcnt;     /* count of symlinks encountered */
1.1       cgd       134:        /*
1.4       mycroft   135:         * Lookup parameters: this structure describes the subset of
                    136:         * information from the nameidata structure that is passed
                    137:         * through the VOP interface.
1.1       cgd       138:         */
1.92      dennis    139:        struct componentname ni_cnd;
1.1       cgd       140: };
                    141:
                    142: /*
                    143:  * namei operations
                    144:  */
                    145: #define        LOOKUP          0       /* perform name lookup only */
                    146: #define        CREATE          1       /* setup for file creation */
                    147: #define        DELETE          2       /* setup for file deletion */
                    148: #define        RENAME          3       /* setup for file renaming */
                    149: #define        OPMASK          3       /* mask for operation */
                    150: /*
1.24      lukem     151:  * namei operational modifier flags, stored in ni_cnd.cn_flags
1.1       cgd       152:  */
1.64      enami     153: #define        LOCKLEAF        0x00000004      /* lock inode on return */
                    154: #define        LOCKPARENT      0x00000008      /* want parent vnode returned locked */
                    155: #define        TRYEMULROOT     0x00000010      /* try relative to emulation root
                    156:                                           first */
                    157: #define        NOCACHE         0x00000020      /* name must not be left in cache */
                    158: #define        FOLLOW          0x00000040      /* follow symbolic links */
                    159: #define        NOFOLLOW        0x00000000      /* do not follow symbolic links
                    160:                                           (pseudo) */
                    161: #define        EMULROOTSET     0x00000080      /* emulation root already
                    162:                                           in ni_erootdir */
1.108     ad        163: #define        LOCKSHARED      0x00000100      /* want shared locks if possible */
1.64      enami     164: #define        NOCHROOT        0x01000000      /* no chroot on abs path lookups */
1.114   ! dholland  165: #define        NONEXCLHACK     0x02000000      /* open wwith O_CREAT but not O_EXCL */
        !           166: #define        MODMASK         0x030001fc      /* mask of operational modifiers */
1.1       cgd       167: /*
                    168:  * Namei parameter descriptors.
                    169:  */
1.108     ad        170: #define        NOCROSSMOUNT    0x0000800       /* do not cross mount points */
                    171: #define        RDONLY          0x0001000       /* lookup with read-only semantics */
1.34      christos  172: #define        ISDOTDOT        0x0002000       /* current component name is .. */
                    173: #define        MAKEENTRY       0x0004000       /* entry is to be added to name cache */
                    174: #define        ISLASTCN        0x0008000       /* this is last component of pathname */
1.112     rin       175: #define        WILLBEDIR       0x0010000       /* new files will be dirs */
1.16      wrstuden  176: #define        ISWHITEOUT      0x0020000       /* found whiteout */
                    177: #define        DOWHITEOUT      0x0040000       /* do whiteouts */
                    178: #define        REQUIREDIR      0x0080000       /* must be a directory */
1.46      chs       179: #define        CREATEDIR       0x0200000       /* trailing slashes are ok */
1.110     christos  180: #define        PARAMASK        0x02ff800       /* mask of parameter descriptors */
1.59      ad        181:
1.4       mycroft   182: /*
1.81      dholland  183:  * Initialization of a nameidata structure.
1.4       mycroft   184:  */
1.69      dholland  185: #define NDINIT(ndp, op, flags, pathbuf) { \
1.4       mycroft   186:        (ndp)->ni_cnd.cn_nameiop = op; \
                    187:        (ndp)->ni_cnd.cn_flags = flags; \
1.85      dholland  188:        (ndp)->ni_atdir = NULL; \
1.69      dholland  189:        (ndp)->ni_pathbuf = pathbuf; \
1.57      pooka     190:        (ndp)->ni_cnd.cn_cred = kauth_cred_get(); \
1.4       mycroft   191: }
1.81      dholland  192:
                    193: /*
                    194:  * Use this to set the start directory for openat()-type operations.
                    195:  */
                    196: #define NDAT(ndp, dir) {                       \
1.85      dholland  197:        (ndp)->ni_atdir = (dir);                \
1.81      dholland  198: }
                    199:
1.1       cgd       200: #endif
                    201:
1.99      christos  202: #ifdef __NAMECACHE_PRIVATE
1.105     ad        203: #include <sys/rbtree.h>
                    204:
1.1       cgd       205: /*
1.99      christos  206:  * For simplicity (and economy of storage), names longer than
                    207:  * a maximum length of NCHNAMLEN are stored in non-pooled storage.
1.1       cgd       208:  */
1.105     ad        209: #define        NCHNAMLEN       sizeof(((struct namecache *)NULL)->nc_name)
1.1       cgd       210:
1.59      ad        211: /*
1.105     ad        212:  * Namecache entry.
                    213:  *
                    214:  * This structure describes the elements in the cache of recent names looked
                    215:  * up by namei.  It's carefully sized to take up 128 bytes on _LP64, to make
                    216:  * good use of space and the CPU caches.  Items used during RB tree lookup
                    217:  * (nc_tree, nc_key) are clustered at the start of the structure.
1.95      riastrad  218:  *
1.105     ad        219:  * Field markings and their corresponding locks:
1.95      riastrad  220:  *
1.108     ad        221:  * -  stable throughout the lifetime of the namecache entry
1.107     ad        222:  * d  protected by nc_dvp->vi_nc_lock
                    223:  * v  protected by nc_vp->vi_nc_listlock
1.105     ad        224:  * l  protected by cache_lru_lock
1.95      riastrad  225:  */
                    226: struct namecache {
1.105     ad        227:        struct  rb_node nc_tree;        /* d  red-black tree, must be first */
1.107     ad        228:        uint64_t nc_key;                /* -  hashed key value */
                    229:        TAILQ_ENTRY(namecache) nc_list; /* v  nc_vp's list of cache entries */
1.105     ad        230:        TAILQ_ENTRY(namecache) nc_lru;  /* l  pseudo-lru chain */
                    231:        struct  vnode *nc_dvp;          /* -  vnode of parent of name */
                    232:        struct  vnode *nc_vp;           /* -  vnode the name refers to */
1.108     ad        233:        int     nc_lrulist;             /* l  which LRU list it's on */
1.106     ad        234:        u_short nc_nlen;                /* -  length of the name */
1.105     ad        235:        char    nc_whiteout;            /* -  true if a whiteout */
                    236:        char    nc_name[41];            /* -  segment name */
1.1       cgd       237: };
1.99      christos  238: #endif
1.1       cgd       239:
1.9       jtc       240: #ifdef _KERNEL
1.19      thorpej   241: #include <sys/pool.h>
                    242:
1.40      thorpej   243: struct mount;
1.59      ad        244: struct cpu_info;
1.40      thorpej   245:
1.54      ad        246: extern pool_cache_t pnbuf_cache;       /* pathname buffer cache */
1.27      thorpej   247:
1.92      dennis    248: #define        PNBUF_GET()     ((char *)pool_cache_get(pnbuf_cache, PR_WAITOK))
                    249: #define        PNBUF_PUT(pnb)  pool_cache_put(pnbuf_cache, (void *)(pnb))
1.19      thorpej   250:
1.65      dholland  251: /*
1.86      manu      252:  * Typesafe flags for namei_simple/nameiat_simple.
1.65      dholland  253:  *
                    254:  * This encoding is not optimal but serves the important purpose of
                    255:  * not being type-compatible with the regular namei flags.
                    256:  */
                    257: struct namei_simple_flags_type; /* Opaque. */
                    258: typedef const struct namei_simple_flags_type *namei_simple_flags_t; /* Gross. */
                    259: extern const namei_simple_flags_t
                    260:        NSM_NOFOLLOW_NOEMULROOT,
                    261:        NSM_NOFOLLOW_TRYEMULROOT,
                    262:        NSM_FOLLOW_NOEMULROOT,
                    263:        NSM_FOLLOW_TRYEMULROOT;
                    264:
                    265: /*
1.86      manu      266:  * namei(at)?_simple_* - the simple cases of namei, with no struct
                    267:  *                       nameidata involved.
1.65      dholland  268:  *
                    269:  * namei_simple_kernel takes a kernel-space path as the first argument.
                    270:  * namei_simple_user takes a user-space path as the first argument.
1.86      manu      271:  * The nameiat_simple_* variants handle relative path using the given
                    272:  * directory vnode instead of current directory.
1.65      dholland  273:  *
                    274:  * A namei call can be converted to namei_simple_* if:
                    275:  *    - the second arg to NDINIT is LOOKUP;
                    276:  *    - it does not need the parent vnode, nd.ni_dvp;
                    277:  *    - the only flags it uses are (NO)FOLLOW and TRYEMULROOT;
                    278:  *    - it does not do anything else gross with the contents of nd.
                    279:  */
                    280: int namei_simple_kernel(const char *, namei_simple_flags_t, struct vnode **);
                    281: int namei_simple_user(const char *, namei_simple_flags_t, struct vnode **);
1.86      manu      282: int nameiat_simple_kernel(struct vnode *, const char *, namei_simple_flags_t,
                    283:     struct vnode **);
                    284: int nameiat_simple_user(struct vnode *, const char *, namei_simple_flags_t,
                    285:     struct vnode **);
1.65      dholland  286:
1.38      perry     287: int    namei(struct nameidata *);
                    288: uint32_t namei_hash(const char *, const char **);
1.67      dholland  289: int    lookup_for_nfsd(struct nameidata *, struct vnode *, int neverfollow);
1.71      dholland  290: int    lookup_for_nfsd_index(struct nameidata *, struct vnode *);
1.73      dholland  291: int    relookup(struct vnode *, struct vnode **, struct componentname *, int);
1.84      dholland  292: void   cache_purge1(struct vnode *, const char *, size_t, int);
1.35      yamt      293: #define        PURGE_PARENTS   1
                    294: #define        PURGE_CHILDREN  2
1.84      dholland  295: #define        cache_purge(vp) cache_purge1((vp),NULL,0,PURGE_PARENTS|PURGE_CHILDREN)
1.94      riastrad  296: bool   cache_lookup(struct vnode *, const char *, size_t, uint32_t, uint32_t,
1.83      dholland  297:                        int *, struct vnode **);
1.94      riastrad  298: bool   cache_lookup_raw(struct vnode *, const char *, size_t, uint32_t,
1.83      dholland  299:                        int *, struct vnode **);
1.105     ad        300: bool   cache_lookup_linked(struct vnode *, const char *, size_t,
                    301:                            struct vnode **, krwlock_t **, kauth_cred_t);
                    302: int    cache_revlookup(struct vnode *, struct vnode **, char **, char *,
1.110     christos  303:                        bool, accmode_t);
1.105     ad        304: int    cache_diraccess(struct vnode *, int);
1.84      dholland  305: void   cache_enter(struct vnode *, struct vnode *,
                    306:                        const char *, size_t, uint32_t);
1.109     ad        307: void   cache_enter_id(struct vnode *, mode_t, uid_t, gid_t, bool);
1.105     ad        308: bool   cache_have_id(struct vnode *);
                    309: void   cache_vnode_init(struct vnode * );
                    310: void   cache_vnode_fini(struct vnode * );
                    311: void   cache_cpu_init(struct cpu_info *);
1.113     ad        312: void   cache_enter_mount(struct vnode *, struct vnode *);
                    313: bool   cache_cross_mount(struct vnode **, krwlock_t **);
                    314: bool   cache_lookup_mount(struct vnode *, struct vnode **);
1.105     ad        315:
1.40      thorpej   316: void   nchinit(void);
1.88      joerg     317: void   namecache_count_pass2(void);
                    318: void   namecache_count_2passes(void);
1.40      thorpej   319: void   cache_purgevfs(struct mount *);
1.78      christos  320: void   namecache_print(struct vnode *, void (*)(const char *, ...)
1.79      christos  321:     __printflike(1, 2));
1.47      elad      322:
1.1       cgd       323: #endif
                    324:
                    325: /*
1.91      dennis    326:  * Stats on usefulness of namei caches.  A couple of structures are
                    327:  * used for counting, with members having the same names but different
                    328:  * types.  Containerize member names with the preprocessor to avoid
1.108     ad        329:  * cut-'n'-paste.
1.91      dennis    330:  */
                    331: #define        _NAMEI_CACHE_STATS(type) {                                      \
1.108     ad        332:        type    ncs_goodhits;   /* hits that we can really use */       \
1.91      dennis    333:        type    ncs_neghits;    /* negative hits that we can use */     \
                    334:        type    ncs_badhits;    /* hits we must drop */                 \
1.108     ad        335:        type    ncs_falsehits;  /* hits with id mismatch */             \
1.91      dennis    336:        type    ncs_miss;       /* misses */                            \
                    337:        type    ncs_long;       /* long names that ignore cache */      \
1.108     ad        338:        type    ncs_pass2;      /* names found with passes == 2 */      \
                    339:        type    ncs_2passes;    /* number of times we attempt it */     \
1.91      dennis    340:        type    ncs_revhits;    /* reverse-cache hits */                \
                    341:        type    ncs_revmiss;    /* reverse-cache misses */              \
1.105     ad        342:        type    ncs_denied;     /* access denied */                     \
1.91      dennis    343: }
                    344:
                    345: /*
                    346:  * Sysctl deals with a uint64_t version of the stats and summary
                    347:  * totals are kept that way.
1.1       cgd       348:  */
1.91      dennis    349: struct nchstats _NAMEI_CACHE_STATS(uint64_t);
1.26      matt      350:
1.51      pooka     351: /* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */
                    352:
                    353: /* Definitions match above, but with NAMEI_ prefix */
                    354: #define NAMEI_LOOKUP   0
                    355: #define NAMEI_CREATE   1
                    356: #define NAMEI_DELETE   2
                    357: #define NAMEI_RENAME   3
                    358: #define NAMEI_OPMASK   3
1.64      enami     359: #define NAMEI_LOCKLEAF 0x00000004
                    360: #define NAMEI_LOCKPARENT       0x00000008
                    361: #define NAMEI_TRYEMULROOT      0x00000010
                    362: #define NAMEI_NOCACHE  0x00000020
                    363: #define NAMEI_FOLLOW   0x00000040
                    364: #define NAMEI_NOFOLLOW 0x00000000
                    365: #define NAMEI_EMULROOTSET      0x00000080
1.108     ad        366: #define NAMEI_LOCKSHARED       0x00000100
1.64      enami     367: #define NAMEI_NOCHROOT 0x01000000
1.114   ! dholland  368: #define NAMEI_NONEXCLHACK      0x02000000
        !           369: #define NAMEI_MODMASK  0x030001fc
1.108     ad        370: #define NAMEI_NOCROSSMOUNT     0x0000800
                    371: #define NAMEI_RDONLY   0x0001000
1.51      pooka     372: #define NAMEI_ISDOTDOT 0x0002000
                    373: #define NAMEI_MAKEENTRY        0x0004000
                    374: #define NAMEI_ISLASTCN 0x0008000
1.112     rin       375: #define NAMEI_WILLBEDIR        0x0010000
1.51      pooka     376: #define NAMEI_ISWHITEOUT       0x0020000
                    377: #define NAMEI_DOWHITEOUT       0x0040000
                    378: #define NAMEI_REQUIREDIR       0x0080000
                    379: #define NAMEI_CREATEDIR        0x0200000
1.111     ad        380: #define NAMEI_PARAMASK 0x02ff800
1.51      pooka     381:
1.2       mycroft   382: #endif /* !_SYS_NAMEI_H_ */

CVSweb <webmaster@jp.NetBSD.org>