1 #ifndef __LINUX_DCACHE_H
2 #define __LINUX_DCACHE_H
6 #include <asm/atomic.h>
7 #include <linux/mount.h>
8 #include <linux/kernel.h>
11 * linux/include/linux/dcache.h
13 * Dirent cache data structures
15 * (C) Copyright 1997 Thomas Schoebel-Theuer,
16 * with heavy changes by Linus Torvalds
19 #define IS_ROOT(x) ((x) == (x)->d_parent)
22 * "quick string" -- eases parameter passing, but more importantly
23 * saves "metadata" about the string (ie length and the hash).
26 const unsigned char * name;
31 struct dentry_stat_t {
34 int age_limit; /* age in seconds */
35 int want_pages; /* pages requested by system */
38 extern struct dentry_stat_t dentry_stat;
40 /* Name hashing routines. Initial hash value */
41 /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */
42 #define init_name_hash() 0
44 /* partial hash update function. Assume roughly 4 bits per character */
45 static __inline__ unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
47 return (prevhash + (c << 4) + (c >> 4)) * 11;
50 /* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
51 static __inline__ unsigned long end_name_hash(unsigned long hash)
53 return (unsigned int) hash;
56 /* Compute the hash for a name string. */
57 static __inline__ unsigned int full_name_hash(const unsigned char * name, unsigned int len)
59 unsigned long hash = init_name_hash();
61 hash = partial_name_hash(*name++, hash);
62 return end_name_hash(hash);
65 #define DNAME_INLINE_LEN 16
70 struct inode * d_inode; /* Where the name belongs to - NULL is negative */
71 struct dentry * d_parent; /* parent directory */
72 struct list_head d_hash; /* lookup hash list */
73 struct list_head d_lru; /* d_count = 0 LRU list */
74 struct list_head d_child; /* child of parent list */
75 struct list_head d_subdirs; /* our children */
76 struct list_head d_alias; /* inode alias list */
79 unsigned long d_time; /* used by d_revalidate */
80 struct dentry_operations *d_op;
81 struct super_block * d_sb; /* The root of the dentry tree */
82 unsigned long d_vfs_flags;
83 void * d_fsdata; /* fs-specific data */
84 unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
87 struct dentry_operations {
88 int (*d_revalidate)(struct dentry *, int);
89 int (*d_hash) (struct dentry *, struct qstr *);
90 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
91 int (*d_delete)(struct dentry *);
92 void (*d_release)(struct dentry *);
93 void (*d_iput)(struct dentry *, struct inode *);
96 /* the dentry parameter passed to d_hash and d_compare is the parent
97 * directory of the entries to be compared. It is used in case these
98 * functions need any directory specific information for determining
99 * equivalency classes. Using the dentry itself might not work, as it
100 * might be a negative dentry which has no information associated with
105 big lock dcache_lock may block
106 d_revalidate: no no yes
114 /* d_flags entries */
115 #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
116 #define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly
117 * renamed" and has to be
118 * deleted on the last dput()
120 #define DCACHE_NFSD_DISCONNECTED 0x0004 /* This dentry is not currently connected to the
121 * dcache tree. Its parent will either be itself,
122 * or will have this flag as well.
123 * If this dentry points to a directory, then
124 * s_nfsd_free_path semaphore will be down
126 #define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
128 extern spinlock_t dcache_lock;
131 * d_drop - drop a dentry
132 * @dentry: dentry to drop
134 * d_drop() unhashes the entry from the parent
135 * dentry hashes, so that it won't be found through
136 * a VFS lookup any more. Note that this is different
137 * from deleting the dentry - d_delete will try to
138 * mark the dentry negative if possible, giving a
139 * successful _negative_ lookup, while d_drop will
140 * just make the cache lookup fail.
142 * d_drop() is used mainly for stuff that wants
143 * to invalidate a dentry for some reason (NFS
144 * timeouts or autofs deletes).
147 static __inline__ void d_drop(struct dentry * dentry)
149 spin_lock(&dcache_lock);
150 list_del(&dentry->d_hash);
151 INIT_LIST_HEAD(&dentry->d_hash);
152 spin_unlock(&dcache_lock);
155 static __inline__ int dname_external(struct dentry *d)
157 return d->d_name.name != d->d_iname;
161 * These are the low-level FS interfaces to the dcache..
163 extern void d_instantiate(struct dentry *, struct inode *);
164 extern void d_delete(struct dentry *);
166 /* allocate/de-allocate */
167 extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
168 extern void shrink_dcache_sb(struct super_block *);
169 extern void shrink_dcache_parent(struct dentry *);
170 extern int d_invalidate(struct dentry *);
172 #define shrink_dcache() prune_dcache(0)
174 /* dcache memory management */
175 extern int shrink_dcache_memory(int, unsigned int);
176 extern void prune_dcache(int);
178 /* icache memory management (defined in linux/fs/inode.c) */
179 extern int shrink_icache_memory(int, int);
180 extern void prune_icache(int);
182 /* quota cache memory management (defined in linux/fs/dquot.c) */
183 extern int shrink_dqcache_memory(int, unsigned int);
185 /* only used at mount-time */
186 extern struct dentry * d_alloc_root(struct inode *);
188 /* <clickety>-<click> the ramfs-type tree */
189 extern void d_genocide(struct dentry *);
191 extern struct dentry *d_find_alias(struct inode *);
192 extern void d_prune_aliases(struct inode *);
194 /* test whether we have any submounts in a subdir tree */
195 extern int have_submounts(struct dentry *);
198 * This adds the entry to the hash queues.
200 extern void d_rehash(struct dentry *);
203 * d_add - add dentry to hash queues
204 * @entry: dentry to add
205 * @inode: The inode to attach to this dentry
207 * This adds the entry to the hash queues and initializes @inode.
208 * The entry was actually filled in earlier during d_alloc().
211 static __inline__ void d_add(struct dentry * entry, struct inode * inode)
213 d_instantiate(entry, inode);
217 /* used for rename() and baskets */
218 extern void d_move(struct dentry *, struct dentry *);
220 /* appendix may either be NULL or be used for transname suffixes */
221 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
223 /* validate "insecure" dentry pointer */
224 extern int d_validate(struct dentry *, struct dentry *);
226 extern char * __d_path(struct dentry *, struct vfsmount *, struct dentry *,
227 struct vfsmount *, char *, int);
229 /* Allocation counts.. */
232 * dget, dget_locked - get a reference to a dentry
233 * @dentry: dentry to get a reference to
235 * Given a dentry or %NULL pointer increment the reference count
236 * if appropriate and return the dentry. A dentry will not be
237 * destroyed when it has references. dget() should never be
238 * called for dentries with zero reference counter. For these cases
239 * (preferably none, functions in dcache.c are sufficient for normal
240 * needs and they take necessary precautions) you should hold dcache_lock
241 * and call dget_locked() instead of dget().
244 static __inline__ struct dentry * dget(struct dentry *dentry)
247 if (!atomic_read(&dentry->d_count))
249 atomic_inc(&dentry->d_count);
254 extern struct dentry * dget_locked(struct dentry *);
257 * d_unhashed - is dentry hashed
258 * @dentry: entry to check
260 * Returns true if the dentry passed is not currently hashed.
263 static __inline__ int d_unhashed(struct dentry *dentry)
265 return list_empty(&dentry->d_hash);
268 extern void dput(struct dentry *);
270 static __inline__ int d_mountpoint(struct dentry *dentry)
272 return dentry->d_mounted;
275 extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *);
276 #endif /* __KERNEL__ */
278 #endif /* __LINUX_DCACHE_H */