1 #ifndef __LINUX_DCACHE_H
2 #define __LINUX_DCACHE_H
3
4 #ifdef __KERNEL__
5
6 #include <asm/atomic.h>
7 #include <linux/mount.h>
8
9 /*
10 * linux/include/linux/dcache.h
11 *
12 * Dirent cache data structures
13 *
14 * (C) Copyright 1997 Thomas Schoebel-Theuer,
15 * with heavy changes by Linus Torvalds
16 */
17
18 #define IS_ROOT(x) ((x) == (x)->d_parent)
19
20 /*
21 * "quick string" -- eases parameter passing, but more importantly
22 * saves "metadata" about the string (ie length and the hash).
23 */
24 struct qstr {
25 const unsigned char * name;
26 unsigned int len;
27 unsigned int hash;
28 };
29
30 /* Name hashing routines. Initial hash value */
31 #define init_name_hash() 0
32
33 /* partial hash update function. Assume roughly 4 bits per character */
34 static __inline__ unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
35 {
36 prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
37 return prevhash ^ c;
38 }
39
40 /* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
41 static __inline__ unsigned long end_name_hash(unsigned long hash)
42 {
43 if (sizeof(hash) > sizeof(unsigned int))
44 hash += hash >> 4*sizeof(hash);
45 return (unsigned int) hash;
46 }
47
48 /* Compute the hash for a name string. */
49 static __inline__ unsigned int full_name_hash(const unsigned char * name, unsigned int len)
50 {
51 unsigned long hash = init_name_hash();
52 while (len--)
53 hash = partial_name_hash(*name++, hash);
54 return end_name_hash(hash);
55 }
56
57 #define DNAME_INLINE_LEN 16
58
59 struct dentry {
60 atomic_t d_count;
61 unsigned int d_flags;
62 struct inode * d_inode; /* Where the name belongs to - NULL is negative */
63 struct dentry * d_parent; /* parent directory */
64 struct list_head d_vfsmnt;
65 struct list_head d_hash; /* lookup hash list */
66 struct list_head d_lru; /* d_count = 0 LRU list */
67 struct list_head d_child; /* child of parent list */
68 struct list_head d_subdirs; /* our children */
69 struct list_head d_alias; /* inode alias list */
70 struct qstr d_name;
71 unsigned long d_time; /* used by d_revalidate */
72 struct dentry_operations *d_op;
73 struct super_block * d_sb; /* The root of the dentry tree */
74 unsigned long d_reftime; /* last time referenced */
75 void * d_fsdata; /* fs-specific data */
76 unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
77 };
78
79 struct dentry_operations {
80 int (*d_revalidate)(struct dentry *, int);
81 int (*d_hash) (struct dentry *, struct qstr *);
82 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
83 int (*d_delete)(struct dentry *);
84 void (*d_release)(struct dentry *);
85 void (*d_iput)(struct dentry *, struct inode *);
86 };
87
88 /* the dentry parameter passed to d_hash and d_compare is the parent
89 * directory of the entries to be compared. It is used in case these
90 * functions need any directory specific information for determining
91 * equivalency classes. Using the dentry itself might not work, as it
92 * might be a negative dentry which has no information associated with
93 * it */
94
95 /*
96 locking rules:
97 big lock dcache_lock may block
98 d_revalidate: no no yes
99 d_hash no no yes
100 d_compare: no yes no
101 d_delete: no yes no
102 d_release: no no yes
103 d_iput: no no yes
104 */
105
106 /* d_flags entries */
107 #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
108 #define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly
109 * renamed" and has to be
110 * deleted on the last dput()
111 */
112 #define DCACHE_NFSD_DISCONNECTED 0x0004 /* This dentry is not currently connected to the
113 * dcache tree. Its parent will either be itself,
114 * or will have this flag as well.
115 * If this dentry points to a directory, then
116 * s_nfsd_free_path semaphore will be down
117 */
118 #define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
119
120 extern spinlock_t dcache_lock;
121
122 /**
123 * d_drop - drop a dentry
124 * @dentry: dentry to drop
125 *
126 * d_drop() unhashes the entry from the parent
127 * dentry hashes, so that it won't be found through
128 * a VFS lookup any more. Note that this is different
129 * from deleting the dentry - d_delete will try to
130 * mark the dentry negative if possible, giving a
131 * successful _negative_ lookup, while d_drop will
132 * just make the cache lookup fail.
133 *
134 * d_drop() is used mainly for stuff that wants
135 * to invalidate a dentry for some reason (NFS
136 * timeouts or autofs deletes).
137 */
138
139 static __inline__ void d_drop(struct dentry * dentry)
140 {
141 spin_lock(&dcache_lock);
142 list_del(&dentry->d_hash);
143 INIT_LIST_HEAD(&dentry->d_hash);
144 spin_unlock(&dcache_lock);
145 }
146
147 static __inline__ int dname_external(struct dentry *d)
148 {
149 return d->d_name.name != d->d_iname;
150 }
151
152 /*
153 * These are the low-level FS interfaces to the dcache..
154 */
155 extern void d_instantiate(struct dentry *, struct inode *);
156 extern void d_delete(struct dentry *);
157
158 /* allocate/de-allocate */
159 extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
160 extern void shrink_dcache_sb(struct super_block *);
161 extern void shrink_dcache_parent(struct dentry *);
162 extern int d_invalidate(struct dentry *);
163
164 #define shrink_dcache() prune_dcache(0)
165 struct zone_struct;
166 /* dcache memory management */
167 extern void shrink_dcache_memory(int, unsigned int);
168 extern void prune_dcache(int);
169
170 /* icache memory management (defined in linux/fs/inode.c) */
171 extern void shrink_icache_memory(int, int);
172 extern void prune_icache(int);
173
174 /* only used at mount-time */
175 extern struct dentry * d_alloc_root(struct inode *);
176
177 /* <clickety>-<click> the ramfs-type tree */
178 extern void d_genocide(struct dentry *);
179
180 extern struct dentry *d_find_alias(struct inode *);
181 extern void d_prune_aliases(struct inode *);
182
183 /* test whether we have any submounts in a subdir tree */
184 extern int have_submounts(struct dentry *);
185
186 /*
187 * This adds the entry to the hash queues.
188 */
189 extern void d_rehash(struct dentry *);
190
191 /**
192 * d_add - add dentry to hash queues
193 * @entry: dentry to add
194 * @inode: The inode to attach to this dentry
195 *
196 * This adds the entry to the hash queues and initializes @inode.
197 * The entry was actually filled in earlier during d_alloc().
198 */
199
200 static __inline__ void d_add(struct dentry * entry, struct inode * inode)
201 {
202 d_instantiate(entry, inode);
203 d_rehash(entry);
204 }
205
206 /* used for rename() and baskets */
207 extern void d_move(struct dentry *, struct dentry *);
208
209 /* appendix may either be NULL or be used for transname suffixes */
210 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
211
212 /* validate "insecure" dentry pointer */
213 extern int d_validate(struct dentry *, struct dentry *, unsigned int, unsigned int);
214
215 extern char * __d_path(struct dentry *, struct vfsmount *, struct dentry *,
216 struct vfsmount *, char *, int);
217
218 /* Allocation counts.. */
219
220 /**
221 * dget, dget_locked - get a reference to a dentry
222 * @dentry: dentry to get a reference to
223 *
224 * Given a dentry or %NULL pointer increment the reference count
225 * if appropriate and return the dentry. A dentry will not be
226 * destroyed when it has references. dget() should never be
227 * called for dentries with zero reference counter. For these cases
228 * (preferably none, functions in dcache.c are sufficient for normal
229 * needs and they take necessary precautions) you should hold dcache_lock
230 * and call dget_locked() instead of dget().
231 */
232
233 static __inline__ struct dentry * dget(struct dentry *dentry)
234 {
235 if (dentry) {
236 if (!atomic_read(&dentry->d_count))
237 BUG();
238 atomic_inc(&dentry->d_count);
239 }
240 return dentry;
241 }
242
243 extern struct dentry * dget_locked(struct dentry *);
244
245 /**
246 * d_unhashed - is dentry hashed
247 * @dentry: entry to check
248 *
249 * Returns true if the dentry passed is not currently hashed.
250 */
251
252 static __inline__ int d_unhashed(struct dentry *dentry)
253 {
254 return list_empty(&dentry->d_hash);
255 }
256
257 extern void dput(struct dentry *);
258
259 static __inline__ int d_mountpoint(struct dentry *dentry)
260 {
261 return !list_empty(&dentry->d_vfsmnt);
262 }
263
264 #endif /* __KERNEL__ */
265
266 #endif /* __LINUX_DCACHE_H */
267
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.