Import 2.1.116pre2
[davej-history.git] / include / linux / dcache.h
blobb546fb5af34f1d118345a43a6ac472d82d250f09
1 #ifndef __LINUX_DCACHE_H
2 #define __LINUX_DCACHE_H
4 #ifdef __KERNEL__
6 /*
7 * linux/include/linux/dcache.h
9 * Directory cache data structures
12 #define D_MAXLEN 1024
14 #define IS_ROOT(x) ((x) == (x)->d_parent)
17 * "quick string" -- eases parameter passing, but more importantly
18 * saves "metadata" about the string (ie length and the hash).
20 struct qstr {
21 const unsigned char * name;
22 unsigned int len;
23 unsigned int hash;
26 /* Name hashing routines. Initial hash value */
27 #define init_name_hash() 0
29 /* partial hash update function. Assume roughly 4 bits per character */
30 static __inline__ unsigned long partial_name_hash(unsigned char c, unsigned long prevhash)
32 prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
33 return prevhash ^ c;
36 /* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
37 static __inline__ unsigned long end_name_hash(unsigned long hash)
39 if (sizeof(hash) > sizeof(unsigned int))
40 hash += hash >> 4*sizeof(hash);
41 return (unsigned int) hash;
44 /* Compute the hash for a name string. */
45 static __inline__ unsigned int full_name_hash(const char * name, unsigned int len)
47 unsigned long hash = init_name_hash();
48 while (len--)
49 hash = partial_name_hash(*name++, hash);
50 return end_name_hash(hash);
53 #define DNAME_INLINE_LEN 16
55 struct dentry {
56 int d_count;
57 unsigned int d_flags;
58 struct inode * d_inode; /* Where the name belongs to - NULL is negative */
59 struct dentry * d_parent; /* parent directory */
60 struct dentry * d_mounts; /* mount information */
61 struct dentry * d_covers;
62 struct list_head d_hash; /* lookup hash list */
63 struct list_head d_lru; /* d_count = 0 LRU list */
64 struct list_head d_child; /* child of parent list */
65 struct list_head d_subdirs; /* our children */
66 struct list_head d_alias; /* inode alias list */
67 struct qstr d_name;
68 unsigned long d_time; /* used by d_revalidate */
69 struct dentry_operations *d_op;
70 struct super_block * d_sb; /* The root of the dentry tree */
71 unsigned long d_reftime; /* last time referenced */
72 void * d_fsdata; /* fs-specific data */
73 unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
76 struct dentry_operations {
77 int (*d_revalidate)(struct dentry *);
78 int (*d_hash) (struct dentry *, struct qstr *);
79 int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
80 void (*d_delete)(struct dentry *);
81 void (*d_release)(struct dentry *);
82 void (*d_iput)(struct dentry *, struct inode *);
85 /* the dentry parameter passed to d_hash and d_compare is the parent
86 * directory of the entries to be compared. It is used in case these
87 * functions need any directory specific information for determining
88 * equivalency classes. Using the dentry itself might not work, as it
89 * might be a negative dentry which has no information associated with
90 * it */
94 /* d_flags entries */
95 #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
96 #define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly
97 * renamed" and has to be
98 * deleted on the last dput()
102 * d_drop() unhashes the entry from the parent
103 * dentry hashes, so that it won't be found through
104 * a VFS lookup any more. Note that this is different
105 * from deleting the dentry - d_delete will try to
106 * mark the dentry negative if possible, giving a
107 * successful _negative_ lookup, while d_drop will
108 * just make the cache lookup fail.
110 * d_drop() is used mainly for stuff that wants
111 * to invalidate a dentry for some reason (NFS
112 * timeouts or autofs deletes).
114 static __inline__ void d_drop(struct dentry * dentry)
116 list_del(&dentry->d_hash);
117 INIT_LIST_HEAD(&dentry->d_hash);
120 static __inline__ int dname_external(struct dentry *d)
122 return d->d_name.name != d->d_iname;
126 * These are the low-level FS interfaces to the dcache..
128 extern void d_instantiate(struct dentry *, struct inode *);
129 extern void d_delete(struct dentry *);
131 /* allocate/de-allocate */
132 extern struct dentry * d_alloc(struct dentry * parent, const struct qstr *name);
133 extern void prune_dcache(int);
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 select_dcache(int, int);
142 extern void shrink_dcache_memory(int, unsigned int);
143 extern void check_dcache_memory(void);
144 extern void free_inode_memory(int); /* defined in fs/inode.c */
146 /* only used at mount-time */
147 extern struct dentry * d_alloc_root(struct inode * root_inode, struct dentry * old_root);
149 /* test whether root is busy without destroying dcache */
150 extern int is_root_busy(struct dentry *);
153 * This adds the entry to the hash queues and initializes "d_inode".
154 * The entry was actually filled in earlier during "d_alloc()"
156 extern void d_add(struct dentry * entry, struct inode * inode);
158 /* used for rename() and baskets */
159 extern void d_move(struct dentry * entry, struct dentry * newdentry);
161 /* appendix may either be NULL or be used for transname suffixes */
162 extern struct dentry * d_lookup(struct dentry * dir, struct qstr * name);
164 /* validate "insecure" dentry pointer */
165 extern int d_validate(struct dentry *dentry, struct dentry *dparent,
166 unsigned int hash, unsigned int len);
168 /* write full pathname into buffer and return start of pathname */
169 extern char * d_path(struct dentry * entry, char * buf, int buflen);
171 /* Allocation counts.. */
172 static __inline__ struct dentry * dget(struct dentry *dentry)
174 if (dentry)
175 dentry->d_count++;
176 return dentry;
179 extern void dput(struct dentry *);
181 #endif /* __KERNEL__ */
183 #endif /* __LINUX_DCACHE_H */