* better
[mascara-docs.git] / i386 / linux-2.3.21 / include / linux / dcache.h
blob0ae06753fc518d744c1b0a865c85287ce5e29efa
1 #ifndef __LINUX_DCACHE_H
2 #define __LINUX_DCACHE_H
4 #ifdef __KERNEL__
6 /*
7 * linux/include/linux/dcache.h
9 * Dirent cache data structures
11 * (C) Copyright 1997 Thomas Schoebel-Theuer,
12 * with heavy changes by Linus Torvalds
15 #define IS_ROOT(x) ((x) == (x)->d_parent)
18 * "quick string" -- eases parameter passing, but more importantly
19 * saves "metadata" about the string (ie length and the hash).
21 struct qstr {
22 const unsigned char * name;
23 unsigned int len;
24 unsigned int hash;
27 /* Name hashing routines. Initial hash value */
28 #define init_name_hash() 0
30 /* partial hash update function. Assume roughly 4 bits per character */
31 static __inline__ unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
33 prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
34 return prevhash ^ c;
37 /* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
38 static __inline__ unsigned long end_name_hash(unsigned long hash)
40 if (sizeof(hash) > sizeof(unsigned int))
41 hash += hash >> 4*sizeof(hash);
42 return (unsigned int) hash;
45 /* Compute the hash for a name string. */
46 static __inline__ unsigned int full_name_hash(const unsigned char * name, unsigned int len)
48 unsigned long hash = init_name_hash();
49 while (len--)
50 hash = partial_name_hash(*name++, hash);
51 return end_name_hash(hash);
54 #define DNAME_INLINE_LEN 16
56 struct dentry {
57 int d_count;
58 unsigned int d_flags;
59 struct inode * d_inode; /* Where the name belongs to - NULL is negative */
60 struct dentry * d_parent; /* parent directory */
61 struct dentry * d_mounts; /* mount information */
62 struct dentry * d_covers;
63 struct list_head d_hash; /* lookup hash list */
64 struct list_head d_lru; /* d_count = 0 LRU list */
65 struct list_head d_child; /* child of parent list */
66 struct list_head d_subdirs; /* our children */
67 struct list_head d_alias; /* inode alias list */
68 struct qstr d_name;
69 unsigned long d_time; /* used by d_revalidate */
70 struct dentry_operations *d_op;
71 struct super_block * d_sb; /* The root of the dentry tree */
72 unsigned long d_reftime; /* last time referenced */
73 void * d_fsdata; /* fs-specific data */
74 unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
77 struct dentry_operations {
78 int (*d_revalidate)(struct dentry *, int);
79 int (*d_hash) (struct dentry *, struct qstr *);
80 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
81 void (*d_delete)(struct dentry *);
82 void (*d_release)(struct dentry *);
83 void (*d_iput)(struct dentry *, struct inode *);
86 /* the dentry parameter passed to d_hash and d_compare is the parent
87 * directory of the entries to be compared. It is used in case these
88 * functions need any directory specific information for determining
89 * equivalency classes. Using the dentry itself might not work, as it
90 * might be a negative dentry which has no information associated with
91 * it */
95 /* d_flags entries */
96 #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
97 #define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly
98 * renamed" and has to be
99 * deleted on the last dput()
103 * d_drop() unhashes the entry from the parent
104 * dentry hashes, so that it won't be found through
105 * a VFS lookup any more. Note that this is different
106 * from deleting the dentry - d_delete will try to
107 * mark the dentry negative if possible, giving a
108 * successful _negative_ lookup, while d_drop will
109 * just make the cache lookup fail.
111 * d_drop() is used mainly for stuff that wants
112 * to invalidate a dentry for some reason (NFS
113 * timeouts or autofs deletes).
115 static __inline__ void d_drop(struct dentry * dentry)
117 list_del(&dentry->d_hash);
118 INIT_LIST_HEAD(&dentry->d_hash);
121 static __inline__ int dname_external(struct dentry *d)
123 return d->d_name.name != d->d_iname;
127 * These are the low-level FS interfaces to the dcache..
129 extern void d_instantiate(struct dentry *, struct inode *);
130 extern void d_delete(struct dentry *);
132 /* allocate/de-allocate */
133 extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
134 extern void shrink_dcache_sb(struct super_block *);
135 extern void shrink_dcache_parent(struct dentry *);
136 extern int d_invalidate(struct dentry *);
138 #define shrink_dcache() prune_dcache(0)
140 /* dcache memory management */
141 extern int shrink_dcache_memory(int, unsigned int);
142 extern void prune_dcache(int);
144 /* icache memory management (defined in linux/fs/inode.c) */
145 extern int shrink_icache_memory(int, int);
146 extern void prune_icache(int);
148 /* only used at mount-time */
149 extern struct dentry * d_alloc_root(struct inode *);
151 /* test whether root is busy without destroying dcache */
152 extern int is_root_busy(struct dentry *);
155 * This adds the entry to the hash queues.
157 extern void d_rehash(struct dentry *);
159 * This adds the entry to the hash queues and initializes "d_inode".
160 * The entry was actually filled in earlier during "d_alloc()"
162 static __inline__ void d_add(struct dentry * entry, struct inode * inode)
164 d_rehash(entry);
165 d_instantiate(entry, inode);
168 /* used for rename() and baskets */
169 extern void d_move(struct dentry *, struct dentry *);
171 /* appendix may either be NULL or be used for transname suffixes */
172 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
174 /* validate "insecure" dentry pointer */
175 extern int d_validate(struct dentry *, struct dentry *, unsigned int, unsigned int);
177 /* write full pathname into buffer and return start of pathname */
178 extern char * d_path(struct dentry *, char *, int);
180 /* Allocation counts.. */
181 static __inline__ struct dentry * dget(struct dentry *dentry)
183 if (dentry)
184 dentry->d_count++;
185 return dentry;
188 extern void dput(struct dentry *);
190 #endif /* __KERNEL__ */
192 #endif /* __LINUX_DCACHE_H */