1 #ifndef __LINUX_DCACHE_H
2 #define __LINUX_DCACHE_H
6 #include <asm/atomic.h>
7 #include <linux/mount.h>
10 * linux/include/linux/dcache.h
12 * Dirent cache data structures
14 * (C) Copyright 1997 Thomas Schoebel-Theuer,
15 * with heavy changes by Linus Torvalds
18 #define IS_ROOT(x) ((x) == (x)->d_parent)
21 * "quick string" -- eases parameter passing, but more importantly
22 * saves "metadata" about the string (ie length and the hash).
25 const unsigned char * name
;
30 /* Name hashing routines. Initial hash value */
31 #define init_name_hash() 0
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
)
36 prevhash
= (prevhash
<< 4) | (prevhash
>> (8*sizeof(unsigned long)-4));
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
)
43 if (sizeof(hash
) > sizeof(unsigned int))
44 hash
+= hash
>> 4*sizeof(hash
);
45 return (unsigned int) hash
;
48 /* Compute the hash for a name string. */
49 static __inline__
unsigned int full_name_hash(const unsigned char * name
, unsigned int len
)
51 unsigned long hash
= init_name_hash();
53 hash
= partial_name_hash(*name
++, hash
);
54 return end_name_hash(hash
);
57 #define DNAME_INLINE_LEN 16
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 */
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 */
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
*);
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
97 big lock dcache_lock may block
98 d_revalidate: no no yes
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()
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
119 extern spinlock_t dcache_lock
;
122 * d_drop - drop a dentry
123 * @dentry: dentry to drop
125 * d_drop() unhashes the entry from the parent
126 * dentry hashes, so that it won't be found through
127 * a VFS lookup any more. Note that this is different
128 * from deleting the dentry - d_delete will try to
129 * mark the dentry negative if possible, giving a
130 * successful _negative_ lookup, while d_drop will
131 * just make the cache lookup fail.
133 * d_drop() is used mainly for stuff that wants
134 * to invalidate a dentry for some reason (NFS
135 * timeouts or autofs deletes).
138 static __inline__
void d_drop(struct dentry
* dentry
)
140 spin_lock(&dcache_lock
);
141 list_del(&dentry
->d_hash
);
142 INIT_LIST_HEAD(&dentry
->d_hash
);
143 spin_unlock(&dcache_lock
);
146 static __inline__
int dname_external(struct dentry
*d
)
148 return d
->d_name
.name
!= d
->d_iname
;
152 * These are the low-level FS interfaces to the dcache..
154 extern void d_instantiate(struct dentry
*, struct inode
*);
155 extern void d_delete(struct dentry
*);
157 /* allocate/de-allocate */
158 extern struct dentry
* d_alloc(struct dentry
*, const struct qstr
*);
159 extern void shrink_dcache_sb(struct super_block
*);
160 extern void shrink_dcache_parent(struct dentry
*);
161 extern int d_invalidate(struct dentry
*);
163 #define shrink_dcache() prune_dcache(0)
165 /* dcache memory management */
166 extern void shrink_dcache_memory(int, unsigned int);
167 extern void prune_dcache(int);
169 /* icache memory management (defined in linux/fs/inode.c) */
170 extern void shrink_icache_memory(int, int);
171 extern void prune_icache(int);
173 /* only used at mount-time */
174 extern struct dentry
* d_alloc_root(struct inode
*);
176 /* <clickety>-<click> the ramfs-type tree */
177 extern void d_genocide(struct dentry
*);
179 extern struct dentry
*d_find_alias(struct inode
*);
180 extern void d_prune_aliases(struct inode
*);
182 /* test whether we have any submounts in a subdir tree */
183 extern int have_submounts(struct dentry
*);
186 * This adds the entry to the hash queues.
188 extern void d_rehash(struct dentry
*);
191 * d_add - add dentry to hash queues
192 * @entry: dentry to add
193 * @inode: The inode to attach to this dentry
195 * This adds the entry to the hash queues and initializes @inode.
196 * The entry was actually filled in earlier during d_alloc().
199 static __inline__
void d_add(struct dentry
* entry
, struct inode
* inode
)
201 d_instantiate(entry
, inode
);
205 /* used for rename() and baskets */
206 extern void d_move(struct dentry
*, struct dentry
*);
208 /* appendix may either be NULL or be used for transname suffixes */
209 extern struct dentry
* d_lookup(struct dentry
*, struct qstr
*);
211 /* validate "insecure" dentry pointer */
212 extern int d_validate(struct dentry
*, struct dentry
*, unsigned int, unsigned int);
214 extern char * __d_path(struct dentry
*, struct vfsmount
*, struct dentry
*,
215 struct vfsmount
*, char *, int);
217 /* Allocation counts.. */
220 * dget, dget_locked - get a reference to a dentry
221 * @dentry: dentry to get a reference to
223 * Given a dentry or %NULL pointer increment the reference count
224 * if appropriate and return the dentry. A dentry will not be
225 * destroyed when it has references. dget() should never be
226 * called for dentries with zero reference counter. For these cases
227 * (preferably none, functions in dcache.c are sufficient for normal
228 * needs and they take necessary precautions) you should hold dcache_lock
229 * and call dget_locked() instead of dget().
232 static __inline__
struct dentry
* dget(struct dentry
*dentry
)
235 if (!atomic_read(&dentry
->d_count
))
237 atomic_inc(&dentry
->d_count
);
242 extern struct dentry
* dget_locked(struct dentry
*);
245 * d_unhashed - is dentry hashed
246 * @dentry: entry to check
248 * Returns true if the dentry passed is not currently hashed.
251 static __inline__
int d_unhashed(struct dentry
*dentry
)
253 return list_empty(&dentry
->d_hash
);
256 extern void dput(struct dentry
*);
258 static __inline__
int d_mountpoint(struct dentry
*dentry
)
260 return !list_empty(&dentry
->d_vfsmnt
);
263 #endif /* __KERNEL__ */
265 #endif /* __LINUX_DCACHE_H */