2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Copyright (c) 1989, 1993
35 * The Regents of the University of California. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * $DragonFly: src/sys/sys/namecache.h,v 1.26 2006/06/04 17:33:36 dillon Exp $
68 #ifndef _SYS_NAMECACHE_H_
69 #define _SYS_NAMECACHE_H_
72 #include <sys/types.h>
75 #include <sys/queue.h>
82 TAILQ_HEAD(namecache_list, namecache);
85 * The namecache structure is used to manage the filesystem namespace. Most
86 * vnodes cached by the system will reference one or more associated namecache
89 * The namecache is disjoint, there may not always be a path to the system
90 * root through nc_parent links. If a namecache entry has no parent, that
91 * entry will not be hashed and can only be 'found' via '.' or '..'.
93 * Because the namecache structure maintains the path through mount points,
94 * null, and union mounts, and other VFS overlays, several namecache
95 * structures may pass through the same vnode. Also note that namespaces
96 * relating to non-existant (i.e. not-yet-created) files/directories may be
97 * locked. Lock coherency is achieved by requiring that the particular
98 * namecache record whos parent represents the physical directory in which
99 * the namespace operation is to occur be the one that is locked. In
100 * overlay cases, the (union, nullfs) VFS, or in namei when crossing a mount
101 * point, may have to obtain multiple namespace record locks to avoid
102 * confusion, but only the one representing the physical directory is passed
103 * into lower layer VOP calls.
105 * Many new API VOP operations do not pass vnodes. In these cases the
106 * operations vector is typically obtained via nc_mount->mnt_vn_use_ops.
109 LIST_ENTRY(namecache) nc_hash; /* hash chain (nc_parent,name) */
110 TAILQ_ENTRY(namecache) nc_entry; /* scan via nc_parent->nc_list */
111 TAILQ_ENTRY(namecache) nc_vnode; /* scan via vnode->v_namecache */
112 struct namecache_list nc_list; /* list of children */
113 struct namecache *nc_parent; /* namecache entry for parent */
114 struct vnode *nc_vp; /* vnode representing name or NULL */
115 int nc_refs; /* ref count prevents deletion */
117 u_char nc_nlen; /* The length of the name, 255 max */
119 char *nc_name; /* Separately allocated seg name */
121 int nc_timeout; /* compared against ticks, or 0 */
122 int nc_exlocks; /* namespace locking */
123 struct thread *nc_locktd; /* namespace locking */
124 struct mount *nc_mount; /* associated mount for vopops */
125 int64_t nc_fsmid; /* filesystem modified id */
128 typedef struct namecache *namecache_t;
131 * Flags in namecache.nc_flag (u_char)
133 #define NCF_LOCKED 0x0001 /* locked namespace */
134 #define NCF_WHITEOUT 0x0002 /* negative entry corresponds to whiteout */
135 #define NCF_UNRESOLVED 0x0004 /* invalid or unresolved entry */
136 #define NCF_MOUNTPT 0x0008 /* mount point */
137 #define NCF_ROOT 0x0010 /* namecache root (static) */
138 #define NCF_HASHED 0x0020 /* namecache entry in hash table */
139 #define NCF_LOCKREQ 0x0040
140 #define NCF_UNUSED080 0x0080
141 #define NCF_ISSYMLINK 0x0100 /* represents a symlink */
142 #define NCF_ISDIR 0x0200 /* represents a directory */
143 #define NCF_DESTROYED 0x0400 /* name association is considered destroyed */
144 #define NCF_FSMID 0x0800 /* FSMID updated */
147 * cache_inval[_vp]() flags
149 #define CINV_DESTROY 0x0001 /* flag so cache_nlookup ignores the ncp */
150 #define CINV_UNUSED02 0x0002
151 #define CINV_CHILDREN 0x0004 /* recursively set children to unresolved */
155 struct componentname;
159 void cache_lock(struct namecache *ncp);
160 int cache_lock_nonblock(struct namecache *ncp);
161 void cache_unlock(struct namecache *ncp);
162 void cache_setvp(struct namecache *ncp, struct vnode *vp);
163 void cache_settimeout(struct namecache *ncp, int nticks);
164 void cache_setunresolved(struct namecache *ncp);
165 struct namecache *cache_nlookup(struct namecache *par, struct nlcomponent *nlc);
166 struct namecache *cache_allocroot(struct mount *mp, struct vnode *vp);
167 int cache_inval(struct namecache *ncp, int flags);
168 int cache_inval_vp(struct vnode *vp, int flags);
169 void vfs_cache_setroot(struct vnode *vp, struct namecache *ncp);
171 int cache_resolve(struct namecache *ncp, struct ucred *cred);
172 void cache_purge(struct vnode *vp);
173 void cache_purgevfs (struct mount *mp);
174 void cache_validate(struct namecache *ncp);
175 int cache_get_nonblock(struct namecache *ncp);
176 void cache_cleanneg(int count);
177 struct namecache *cache_get(struct namecache *ncp);
178 struct namecache *cache_hold(struct namecache *ncp);
179 void cache_put(struct namecache *ncp);
180 void cache_drop(struct namecache *ncp);
181 void cache_rename(struct namecache *fncp, struct namecache *tncp);
182 int cache_vget(struct namecache *, struct ucred *, int, struct vnode **);
183 int cache_vref(struct namecache *, struct ucred *, struct vnode **);
184 struct namecache *cache_fromdvp(struct vnode *, struct ucred *, int);
185 int cache_fullpath(struct proc *, struct namecache *, char **, char **);
186 void cache_update_fsmid(struct namecache *);
187 void cache_update_fsmid_vp(struct vnode *);
188 int64_t cache_sync_fsmid_vp(struct vnode *);
189 int cache_check_fsmid_vp(struct vnode *, int64_t *);
190 int64_t cache_getnewfsmid(void);