1 Index: linux-2.4.29/fs/ext3/dir.c
2 ===================================================================
3 --- linux-2.4.29.orig/fs/ext3/dir.c 2005-04-07 18:53:53.000000000 +0300
4 +++ linux-2.4.29/fs/ext3/dir.c 2005-05-03 16:34:05.481747664 +0300
8 #include <linux/ext3_fs.h>
9 +#include <linux/slab.h>
10 +#include <linux/rbtree.h>
12 static unsigned char ext3_filetype_table[] = {
13 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
16 static int ext3_readdir(struct file *, void *, filldir_t);
17 +static int ext3_dx_readdir(struct file * filp,
18 + void * dirent, filldir_t filldir);
20 struct file_operations ext3_dir_operations = {
21 read: generic_read_dir,
23 fsync: ext3_sync_file, /* BKL held */
27 +static unsigned char get_dtype(struct super_block *sb, int filetype)
29 + if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE) ||
30 + (filetype >= EXT3_FT_MAX))
33 + return (ext3_filetype_table[filetype]);
37 int ext3_check_dir_entry (const char * function, struct inode * dir,
38 struct ext3_dir_entry_2 * de,
39 struct buffer_head * bh,
45 + err = ext3_dx_readdir(filp, dirent, filldir);
46 + if (err != ERR_BAD_DX_DIR)
49 + * We don't set the inode dirty flag since it's not
50 + * critical that it get flushed back to the disk.
52 + EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL;
56 offset = filp->f_pos & (sb->s_blocksize - 1);
58 * during the copy operation.
60 unsigned long version = filp->f_version;
61 - unsigned char d_type = DT_UNKNOWN;
63 - if (EXT3_HAS_INCOMPAT_FEATURE(sb,
64 - EXT3_FEATURE_INCOMPAT_FILETYPE)
65 - && de->file_type < EXT3_FT_MAX)
67 - ext3_filetype_table[de->file_type];
68 error = filldir(dirent, de->name,
71 le32_to_cpu(de->inode),
73 + get_dtype(sb, de->file_type));
76 if (version != filp->f_version)
82 +#ifdef CONFIG_EXT3_INDEX
84 + * These functions convert from the major/minor hash to an f_pos
87 + * Currently we only use major hash numer. This is unfortunate, but
88 + * on 32-bit machines, the same VFS interface is used for lseek and
89 + * llseek, so if we use the 64 bit offset, then the 32-bit versions of
90 + * lseek/telldir/seekdir will blow out spectacularly, and from within
91 + * the ext2 low-level routine, we don't know if we're being called by
92 + * a 64-bit version of the system call or the 32-bit version of the
93 + * system call. Worse yet, NFSv2 only allows for a 32-bit readdir
96 +#define hash2pos(major, minor) (major >> 1)
97 +#define pos2maj_hash(pos) ((pos << 1) & 0xffffffff)
98 +#define pos2min_hash(pos) (0)
101 + * This structure holds the nodes of the red-black tree used to store
102 + * the directory entry in hash order.
108 + struct fname *next;
116 + * This functoin implements a non-recursive way of freeing all of the
117 + * nodes in the red-black tree.
119 +static void free_rb_tree_fname(rb_root_t *root)
121 + rb_node_t *n = root->rb_node;
123 + struct fname *fname;
126 + /* Do the node's children first */
127 + if ((n)->rb_left) {
136 + * The node has no children; free it, and then zero
137 + * out parent's link to it. Finally go to the
138 + * beginning of the loop and try to free the parent
141 + parent = n->rb_parent;
142 + fname = rb_entry(n, struct fname, rb_hash);
146 + else if (parent->rb_left == n)
147 + parent->rb_left = 0;
148 + else if (parent->rb_right == n)
149 + parent->rb_right = 0;
156 +struct dir_private_info *create_dir_info(loff_t pos)
158 + struct dir_private_info *p;
160 + p = kmalloc(sizeof(struct dir_private_info), GFP_KERNEL);
163 + p->root.rb_node = 0;
165 + p->extra_fname = 0;
167 + p->curr_hash = pos2maj_hash(pos);
168 + p->curr_minor_hash = pos2min_hash(pos);
173 +void ext3_htree_free_dir_info(struct dir_private_info *p)
175 + free_rb_tree_fname(&p->root);
180 + * Given a directory entry, enter it into the fname rb tree.
182 +int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
184 + struct ext3_dir_entry_2 *dirent)
186 + rb_node_t **p, *parent = NULL;
187 + struct fname * fname, *new_fn;
188 + struct dir_private_info *info;
191 + info = (struct dir_private_info *) dir_file->private_data;
192 + p = &info->root.rb_node;
194 + /* Create and allocate the fname structure */
195 + len = sizeof(struct fname) + dirent->name_len + 1;
196 + new_fn = kmalloc(len, GFP_KERNEL);
199 + memset(new_fn, 0, len);
200 + new_fn->hash = hash;
201 + new_fn->minor_hash = minor_hash;
202 + new_fn->inode = le32_to_cpu(dirent->inode);
203 + new_fn->name_len = dirent->name_len;
204 + new_fn->file_type = dirent->file_type;
205 + memcpy(new_fn->name, dirent->name, dirent->name_len);
206 + new_fn->name[dirent->name_len] = 0;
210 + fname = rb_entry(parent, struct fname, rb_hash);
213 + * If the hash and minor hash match up, then we put
214 + * them on a linked list. This rarely happens...
216 + if ((new_fn->hash == fname->hash) &&
217 + (new_fn->minor_hash == fname->minor_hash)) {
218 + new_fn->next = fname->next;
219 + fname->next = new_fn;
223 + if (new_fn->hash < fname->hash)
224 + p = &(*p)->rb_left;
225 + else if (new_fn->hash > fname->hash)
226 + p = &(*p)->rb_right;
227 + else if (new_fn->minor_hash < fname->minor_hash)
228 + p = &(*p)->rb_left;
229 + else /* if (new_fn->minor_hash > fname->minor_hash) */
230 + p = &(*p)->rb_right;
233 + rb_link_node(&new_fn->rb_hash, parent, p);
234 + rb_insert_color(&new_fn->rb_hash, &info->root);
241 + * This is a helper function for ext3_dx_readdir. It calls filldir
242 + * for all entres on the fname linked list. (Normally there is only
243 + * one entry on the linked list, unless there are 62 bit hash collisions.)
245 +static int call_filldir(struct file * filp, void * dirent,
246 + filldir_t filldir, struct fname *fname)
248 + struct dir_private_info *info = filp->private_data;
250 + struct inode *inode = filp->f_dentry->d_inode;
251 + struct super_block * sb;
257 + printk("call_filldir: called with null fname?!?\n");
260 + curr_pos = hash2pos(fname->hash, fname->minor_hash);
262 + error = filldir(dirent, fname->name,
263 + fname->name_len, curr_pos,
265 + get_dtype(sb, fname->file_type));
267 + filp->f_pos = curr_pos;
268 + info->extra_fname = fname->next;
271 + fname = fname->next;
276 +static int ext3_dx_readdir(struct file * filp,
277 + void * dirent, filldir_t filldir)
279 + struct dir_private_info *info = filp->private_data;
280 + struct inode *inode = filp->f_dentry->d_inode;
281 + struct fname *fname;
285 + info = create_dir_info(filp->f_pos);
288 + filp->private_data = info;
291 + /* Some one has messed with f_pos; reset the world */
292 + if (info->last_pos != filp->f_pos) {
293 + free_rb_tree_fname(&info->root);
294 + info->curr_node = 0;
295 + info->extra_fname = 0;
296 + info->curr_hash = pos2maj_hash(filp->f_pos);
297 + info->curr_minor_hash = pos2min_hash(filp->f_pos);
301 + * If there are any leftover names on the hash collision
302 + * chain, return them first.
304 + if (info->extra_fname &&
305 + call_filldir(filp, dirent, filldir, info->extra_fname))
308 + if (!info->curr_node)
309 + info->curr_node = rb_first(&info->root);
313 + * Fill the rbtree if we have no more entries,
314 + * or the inode has changed since we last read in the
317 + if ((!info->curr_node) ||
318 + (filp->f_version != inode->i_version)) {
319 + info->curr_node = 0;
320 + free_rb_tree_fname(&info->root);
321 + filp->f_version = inode->i_version;
322 + ret = ext3_htree_fill_tree(filp, info->curr_hash,
323 + info->curr_minor_hash,
329 + info->curr_node = rb_first(&info->root);
332 + fname = rb_entry(info->curr_node, struct fname, rb_hash);
333 + info->curr_hash = fname->hash;
334 + info->curr_minor_hash = fname->minor_hash;
335 + if (call_filldir(filp, dirent, filldir, fname))
338 + info->curr_node = rb_next(info->curr_node);
339 + if (!info->curr_node) {
340 + info->curr_hash = info->next_hash;
341 + info->curr_minor_hash = 0;
345 + info->last_pos = filp->f_pos;
346 + UPDATE_ATIME(inode);
350 Index: linux-2.4.29/fs/ext3/file.c
351 ===================================================================
352 --- linux-2.4.29.orig/fs/ext3/file.c 2005-04-07 18:55:11.000000000 +0300
353 +++ linux-2.4.29/fs/ext3/file.c 2005-05-03 16:29:50.563501128 +0300
356 if (filp->f_mode & FMODE_WRITE)
357 ext3_discard_prealloc (inode);
358 + if (is_dx(inode) && filp->private_data)
359 + ext3_htree_free_dir_info(filp->private_data);
364 Index: linux-2.4.29/fs/ext3/hash.c
365 ===================================================================
366 --- linux-2.4.29.orig/fs/ext3/hash.c 2005-05-03 16:29:50.539504776 +0300
367 +++ linux-2.4.29/fs/ext3/hash.c 2005-05-03 16:29:50.565500824 +0300
370 + * linux/fs/ext3/hash.c
372 + * Copyright (C) 2002 by Theodore Ts'o
374 + * This file is released under the GPL v2.
376 + * This file may be redistributed under the terms of the GNU Public
380 +#include <linux/fs.h>
381 +#include <linux/jbd.h>
382 +#include <linux/sched.h>
383 +#include <linux/ext3_fs.h>
385 +#define DELTA 0x9E3779B9
387 +static void TEA_transform(__u32 buf[4], __u32 const in[])
390 + __u32 b0 = buf[0], b1 = buf[1];
391 + __u32 a = in[0], b = in[1], c = in[2], d = in[3];
396 + b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);
397 + b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);
404 +/* F, G and H are basic MD4 functions: selection, majority, parity */
405 +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
406 +#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
407 +#define H(x, y, z) ((x) ^ (y) ^ (z))
410 + * The generic round function. The application is so specific that
411 + * we don't bother protecting all the arguments with parens, as is generally
412 + * good macro practice, in favor of extra legibility.
413 + * Rotation is separate from addition to prevent recomputation
415 +#define ROUND(f, a, b, c, d, x, s) \
416 + (a += f(b, c, d) + x, a = (a << s) | (a >> (32-s)))
418 +#define K2 013240474631UL
419 +#define K3 015666365641UL
422 + * Basic cut-down MD4 transform. Returns only 32 bits of result.
424 +static void halfMD4Transform (__u32 buf[4], __u32 const in[])
426 + __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
429 + ROUND(F, a, b, c, d, in[0] + K1, 3);
430 + ROUND(F, d, a, b, c, in[1] + K1, 7);
431 + ROUND(F, c, d, a, b, in[2] + K1, 11);
432 + ROUND(F, b, c, d, a, in[3] + K1, 19);
433 + ROUND(F, a, b, c, d, in[4] + K1, 3);
434 + ROUND(F, d, a, b, c, in[5] + K1, 7);
435 + ROUND(F, c, d, a, b, in[6] + K1, 11);
436 + ROUND(F, b, c, d, a, in[7] + K1, 19);
439 + ROUND(G, a, b, c, d, in[1] + K2, 3);
440 + ROUND(G, d, a, b, c, in[3] + K2, 5);
441 + ROUND(G, c, d, a, b, in[5] + K2, 9);
442 + ROUND(G, b, c, d, a, in[7] + K2, 13);
443 + ROUND(G, a, b, c, d, in[0] + K2, 3);
444 + ROUND(G, d, a, b, c, in[2] + K2, 5);
445 + ROUND(G, c, d, a, b, in[4] + K2, 9);
446 + ROUND(G, b, c, d, a, in[6] + K2, 13);
449 + ROUND(H, a, b, c, d, in[3] + K3, 3);
450 + ROUND(H, d, a, b, c, in[7] + K3, 9);
451 + ROUND(H, c, d, a, b, in[2] + K3, 11);
452 + ROUND(H, b, c, d, a, in[6] + K3, 15);
453 + ROUND(H, a, b, c, d, in[1] + K3, 3);
454 + ROUND(H, d, a, b, c, in[5] + K3, 9);
455 + ROUND(H, c, d, a, b, in[0] + K3, 11);
456 + ROUND(H, b, c, d, a, in[4] + K3, 15);
472 +/* The old legacy hash */
473 +static __u32 dx_hack_hash (const char *name, int len)
475 + __u32 hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
477 + __u32 hash = hash1 + (hash0 ^ (*name++ * 7152373));
479 + if (hash & 0x80000000) hash -= 0x7fffffff;
483 + return (hash0 << 1);
486 +static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
491 + pad = (__u32)len | ((__u32)len << 8);
497 + for (i=0; i < len; i++) {
500 + val = msg[i] + (val << 8);
501 + if ((i % 4) == 3) {
514 + * Returns the hash of a filename. If len is 0 and name is NULL, then
515 + * this function can be used to test whether or not a hash version is
518 + * The seed is an 4 longword (32 bits) "secret" which can be used to
519 + * uniquify a hash. If the seed is all zero's, then some default seed
522 + * A particular hash version specifies whether or not the seed is
523 + * represented, and whether or not the returned hash is 32 bits or 64
524 + * bits. 32 bit hashes will return 0 for the minor hash.
526 +int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
529 + __u32 minor_hash = 0;
532 + __u32 in[8], buf[4];
534 + /* Initialize the default seed for the hash checksum functions */
535 + buf[0] = 0x67452301;
536 + buf[1] = 0xefcdab89;
537 + buf[2] = 0x98badcfe;
538 + buf[3] = 0x10325476;
540 + /* Check to see if the seed is all zero's */
542 + for (i=0; i < 4; i++) {
543 + if (hinfo->seed[i])
547 + memcpy(buf, hinfo->seed, sizeof(buf));
550 + switch (hinfo->hash_version) {
551 + case DX_HASH_LEGACY:
552 + hash = dx_hack_hash(name, len);
554 + case DX_HASH_HALF_MD4:
557 + str2hashbuf(p, len, in, 8);
558 + halfMD4Transform(buf, in);
562 + minor_hash = buf[2];
568 + str2hashbuf(p, len, in, 4);
569 + TEA_transform(buf, in);
574 + minor_hash = buf[1];
580 + hinfo->hash = hash & ~1;
581 + hinfo->minor_hash = minor_hash;
584 Index: linux-2.4.29/fs/ext3/Makefile
585 ===================================================================
586 --- linux-2.4.29.orig/fs/ext3/Makefile 2005-04-07 18:59:19.000000000 +0300
587 +++ linux-2.4.29/fs/ext3/Makefile 2005-05-03 16:29:50.565500824 +0300
589 export-objs := super.o inode.o
591 obj-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
592 - ioctl.o namei.o super.o symlink.o
593 + ioctl.o namei.o super.o symlink.o hash.o
596 include $(TOPDIR)/Rules.make
597 Index: linux-2.4.29/fs/ext3/namei.c
598 ===================================================================
599 --- linux-2.4.29.orig/fs/ext3/namei.c 2005-04-07 18:53:59.000000000 +0300
600 +++ linux-2.4.29/fs/ext3/namei.c 2005-05-03 16:29:50.576499152 +0300
602 * David S. Miller (davem@caip.rutgers.edu), 1995
603 * Directory entry file type support and forward compatibility hooks
604 * for B-tree directories by Theodore Ts'o (tytso@mit.edu), 1998
605 + * Hash Tree Directory indexing (c)
606 + * Daniel Phillips, 2001
607 + * Hash Tree Directory indexing porting
608 + * Christopher Li, 2002
609 + * Hash Tree Directory indexing cleanup
610 + * Theodore Ts'o, 2002
613 #include <linux/fs.h>
615 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
616 #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
618 +static struct buffer_head *ext3_append(handle_t *handle,
619 + struct inode *inode,
620 + u32 *block, int *err)
622 + struct buffer_head *bh;
624 + *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
626 + if ((bh = ext3_bread(handle, inode, *block, 1, err))) {
627 + inode->i_size += inode->i_sb->s_blocksize;
628 + EXT3_I(inode)->i_disksize = inode->i_size;
629 + ext3_journal_get_write_access(handle,bh);
635 +#define assert(test) J_ASSERT(test)
639 +#define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
642 +typedef struct { u32 v; } le_u32;
643 +typedef struct { u16 v; } le_u16;
646 +#define dxtrace(command) command
648 +#define dxtrace(command)
659 +struct dx_countlimit
672 + * dx_root_info is laid out so that if it should somehow get overlaid by a
673 + * dirent the two low bits of the hash version will be zero. Therefore, the
674 + * hash version mod 4 should never be 0. Sincerely, the paranoia department.
679 + struct fake_dirent dot;
681 + struct fake_dirent dotdot;
682 + char dotdot_name[4];
683 + struct dx_root_info
685 + le_u32 reserved_zero;
687 + u8 info_length; /* 8 */
688 + u8 indirect_levels;
692 + struct dx_entry entries[0];
697 + struct fake_dirent fake;
698 + struct dx_entry entries[0];
704 + struct buffer_head *bh;
705 + struct dx_entry *entries;
706 + struct dx_entry *at;
715 +#ifdef CONFIG_EXT3_INDEX
716 +static inline unsigned dx_get_block (struct dx_entry *entry);
717 +static void dx_set_block (struct dx_entry *entry, unsigned value);
718 +static inline unsigned dx_get_hash (struct dx_entry *entry);
719 +static void dx_set_hash (struct dx_entry *entry, unsigned value);
720 +static unsigned dx_get_count (struct dx_entry *entries);
721 +static unsigned dx_get_limit (struct dx_entry *entries);
722 +static void dx_set_count (struct dx_entry *entries, unsigned value);
723 +static void dx_set_limit (struct dx_entry *entries, unsigned value);
724 +static unsigned dx_root_limit (struct inode *dir, unsigned infosize);
725 +static unsigned dx_node_limit (struct inode *dir);
726 +static struct dx_frame *dx_probe(struct dentry *dentry,
728 + struct dx_hash_info *hinfo,
729 + struct dx_frame *frame,
731 +static void dx_release (struct dx_frame *frames);
732 +static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
733 + struct dx_hash_info *hinfo, struct dx_map_entry map[]);
734 +static void dx_sort_map(struct dx_map_entry *map, unsigned count);
735 +static struct ext3_dir_entry_2 *dx_move_dirents (char *from, char *to,
736 + struct dx_map_entry *offsets, int count);
737 +static struct ext3_dir_entry_2* dx_pack_dirents (char *base, int size);
738 +static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block);
739 +static int ext3_htree_next_block(struct inode *dir, __u32 hash,
740 + struct dx_frame *frame,
741 + struct dx_frame *frames, int *err,
742 + __u32 *start_hash);
743 +static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
744 + struct ext3_dir_entry_2 **res_dir, int *err);
745 +static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
746 + struct inode *inode);
749 + * Future: use high four bits of block for coalesce-on-delete flags
750 + * Mask them off for now.
753 +static inline unsigned dx_get_block (struct dx_entry *entry)
755 + return le32_to_cpu(entry->block.v) & 0x00ffffff;
758 +static inline void dx_set_block (struct dx_entry *entry, unsigned value)
760 + entry->block.v = cpu_to_le32(value);
763 +static inline unsigned dx_get_hash (struct dx_entry *entry)
765 + return le32_to_cpu(entry->hash.v);
768 +static inline void dx_set_hash (struct dx_entry *entry, unsigned value)
770 + entry->hash.v = cpu_to_le32(value);
773 +static inline unsigned dx_get_count (struct dx_entry *entries)
775 + return le16_to_cpu(((struct dx_countlimit *) entries)->count.v);
778 +static inline unsigned dx_get_limit (struct dx_entry *entries)
780 + return le16_to_cpu(((struct dx_countlimit *) entries)->limit.v);
783 +static inline void dx_set_count (struct dx_entry *entries, unsigned value)
785 + ((struct dx_countlimit *) entries)->count.v = cpu_to_le16(value);
788 +static inline void dx_set_limit (struct dx_entry *entries, unsigned value)
790 + ((struct dx_countlimit *) entries)->limit.v = cpu_to_le16(value);
793 +static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize)
795 + unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(1) -
796 + EXT3_DIR_REC_LEN(2) - infosize;
797 + return 0? 20: entry_space / sizeof(struct dx_entry);
800 +static inline unsigned dx_node_limit (struct inode *dir)
802 + unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(0);
803 + return 0? 22: entry_space / sizeof(struct dx_entry);
817 +static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext3_dir_entry_2 *de,
818 + int size, int show_names)
820 + unsigned names = 0, space = 0;
821 + char *base = (char *) de;
822 + struct dx_hash_info h = *hinfo;
825 + while ((char *) de < base + size)
831 + int len = de->name_len;
832 + char *name = de->name;
833 + while (len--) printk("%c", *name++);
834 + ext3fs_dirhash(de->name, de->name_len, &h);
835 + printk(":%x.%u ", h.hash,
836 + ((char *) de - base));
838 + space += EXT3_DIR_REC_LEN(de->name_len);
841 + de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
843 + printk("(%i)\n", names);
844 + return (struct stats) { names, space, 1 };
847 +struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
848 + struct dx_entry *entries, int levels)
850 + unsigned blocksize = dir->i_sb->s_blocksize;
851 + unsigned count = dx_get_count (entries), names = 0, space = 0, i;
852 + unsigned bcount = 0;
853 + struct buffer_head *bh;
855 + printk("%i indexed blocks...\n", count);
856 + for (i = 0; i < count; i++, entries++)
858 + u32 block = dx_get_block(entries), hash = i? dx_get_hash(entries): 0;
859 + u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
860 + struct stats stats;
861 + printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
862 + if (!(bh = ext3_bread (NULL,dir, block, 0,&err))) continue;
864 + dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
865 + dx_show_leaf(hinfo, (struct ext3_dir_entry_2 *) bh->b_data, blocksize, 0);
866 + names += stats.names;
867 + space += stats.space;
868 + bcount += stats.bcount;
872 + printk("%snames %u, fullness %u (%u%%)\n", levels?"":" ",
873 + names, space/bcount,(space/bcount)*100/blocksize);
874 + return (struct stats) { names, space, bcount};
876 +#endif /* DX_DEBUG */
879 + * Probe for a directory leaf block to search.
881 + * dx_probe can return ERR_BAD_DX_DIR, which means there was a format
882 + * error in the directory index, and the caller should fall back to
883 + * searching the directory normally. The callers of dx_probe **MUST**
884 + * check for this error code, and make sure it never gets reflected
885 + * back to userspace.
887 +static struct dx_frame *
888 +dx_probe(struct dentry *dentry, struct inode *dir,
889 + struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
891 + unsigned count, indirect;
892 + struct dx_entry *at, *entries, *p, *q, *m;
893 + struct dx_root *root;
894 + struct buffer_head *bh;
895 + struct dx_frame *frame = frame_in;
900 + dir = dentry->d_parent->d_inode;
901 + if (!(bh = ext3_bread (NULL,dir, 0, 0, err)))
903 + root = (struct dx_root *) bh->b_data;
904 + if (root->info.hash_version != DX_HASH_TEA &&
905 + root->info.hash_version != DX_HASH_HALF_MD4 &&
906 + root->info.hash_version != DX_HASH_LEGACY) {
907 + ext3_warning(dir->i_sb, __FUNCTION__,
908 + "Unrecognised inode hash code %d",
909 + root->info.hash_version);
911 + *err = ERR_BAD_DX_DIR;
914 + hinfo->hash_version = root->info.hash_version;
915 + hinfo->seed = dir->i_sb->u.ext3_sb.s_hash_seed;
917 + ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
918 + hash = hinfo->hash;
920 + if (root->info.unused_flags & 1) {
921 + ext3_warning(dir->i_sb, __FUNCTION__,
922 + "Unimplemented inode hash flags: %#06x",
923 + root->info.unused_flags);
925 + *err = ERR_BAD_DX_DIR;
929 + if ((indirect = root->info.indirect_levels) > 1) {
930 + ext3_warning(dir->i_sb, __FUNCTION__,
931 + "Unimplemented inode hash depth: %#06x",
932 + root->info.indirect_levels);
934 + *err = ERR_BAD_DX_DIR;
938 + entries = (struct dx_entry *) (((char *)&root->info) +
939 + root->info.info_length);
940 + assert(dx_get_limit(entries) == dx_root_limit(dir,
941 + root->info.info_length));
942 + dxtrace (printk("Look up %x", hash));
945 + count = dx_get_count(entries);
946 + assert (count && count <= dx_get_limit(entries));
948 + q = entries + count - 1;
952 + dxtrace(printk("."));
953 + if (dx_get_hash(m) > hash)
959 + if (0) // linear search cross check
961 + unsigned n = count - 1;
965 + dxtrace(printk(","));
966 + if (dx_get_hash(++at) > hash)
972 + assert (at == p - 1);
976 + dxtrace(printk(" %x->%u\n", at == entries? 0: dx_get_hash(at), dx_get_block(at)));
978 + frame->entries = entries;
980 + if (!indirect--) return frame;
981 + if (!(bh = ext3_bread (NULL,dir, dx_get_block(at), 0, err)))
983 + at = entries = ((struct dx_node *) bh->b_data)->entries;
984 + assert (dx_get_limit(entries) == dx_node_limit (dir));
988 + while (frame >= frame_in) {
996 +static void dx_release (struct dx_frame *frames)
998 + if (frames[0].bh == NULL)
1001 + if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
1002 + brelse(frames[1].bh);
1003 + brelse(frames[0].bh);
1007 + * This function increments the frame pointer to search the next leaf
1008 + * block, and reads in the necessary intervening nodes if the search
1009 + * should be necessary. Whether or not the search is necessary is
1010 + * controlled by the hash parameter. If the hash value is even, then
1011 + * the search is only continued if the next block starts with that
1012 + * hash value. This is used if we are searching for a specific file.
1014 + * If the hash value is HASH_NB_ALWAYS, then always go to the next block.
1016 + * This function returns 1 if the caller should continue to search,
1017 + * or 0 if it should not. If there is an error reading one of the
1018 + * index blocks, it will return -1.
1020 + * If start_hash is non-null, it will be filled in with the starting
1021 + * hash of the next page.
1023 +static int ext3_htree_next_block(struct inode *dir, __u32 hash,
1024 + struct dx_frame *frame,
1025 + struct dx_frame *frames, int *err,
1026 + __u32 *start_hash)
1028 + struct dx_frame *p;
1029 + struct buffer_head *bh;
1030 + int num_frames = 0;
1036 + * Find the next leaf page by incrementing the frame pointer.
1037 + * If we run out of entries in the interior node, loop around and
1038 + * increment pointer in the parent node. When we break out of
1039 + * this loop, num_frames indicates the number of interior
1040 + * nodes need to be read.
1043 + if (++(p->at) < p->entries + dx_get_count(p->entries))
1052 + * If the hash is 1, then continue only if the next page has a
1053 + * continuation hash of any value. This is used for readdir
1054 + * handling. Otherwise, check to see if the hash matches the
1055 + * desired contiuation hash. If it doesn't, return since
1056 + * there's no point to read in the successive index pages.
1058 + bhash = dx_get_hash(p->at);
1060 + *start_hash = bhash;
1061 + if ((hash & 1) == 0) {
1062 + if ((bhash & ~1) != hash)
1066 + * If the hash is HASH_NB_ALWAYS, we always go to the next
1067 + * block so no check is necessary
1069 + while (num_frames--) {
1070 + if (!(bh = ext3_bread(NULL, dir, dx_get_block(p->at),
1072 + return -1; /* Failure */
1076 + p->at = p->entries = ((struct dx_node *) bh->b_data)->entries;
1083 + * p is at least 6 bytes before the end of page
1085 +static inline struct ext3_dir_entry_2 *ext3_next_entry(struct ext3_dir_entry_2 *p)
1087 + return (struct ext3_dir_entry_2 *)((char*)p + le16_to_cpu(p->rec_len));
1091 + * This function fills a red-black tree with information from a
1092 + * directory. We start scanning the directory in hash order, starting
1093 + * at start_hash and start_minor_hash.
1095 + * This function returns the number of entries inserted into the tree,
1096 + * or a negative error code.
1098 +int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
1099 + __u32 start_minor_hash, __u32 *next_hash)
1101 + struct dx_hash_info hinfo;
1102 + struct buffer_head *bh;
1103 + struct ext3_dir_entry_2 *de, *top;
1104 + static struct dx_frame frames[2], *frame;
1105 + struct inode *dir;
1111 + dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
1112 + start_minor_hash));
1113 + dir = dir_file->f_dentry->d_inode;
1114 + hinfo.hash = start_hash;
1115 + hinfo.minor_hash = 0;
1116 + frame = dx_probe(0, dir_file->f_dentry->d_inode, &hinfo, frames, &err);
1120 + /* Add '.' and '..' from the htree header */
1121 + if (!start_hash && !start_minor_hash) {
1122 + de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data;
1123 + if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
1125 + de = ext3_next_entry(de);
1126 + if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
1132 + block = dx_get_block(frame->at);
1133 + dxtrace(printk("Reading block %d\n", block));
1134 + if (!(bh = ext3_bread (NULL, dir, block, 0, &err)))
1137 + de = (struct ext3_dir_entry_2 *) bh->b_data;
1138 + top = (struct ext3_dir_entry_2 *) ((char *) de + dir->i_sb->s_blocksize -
1139 + EXT3_DIR_REC_LEN(0));
1140 + for (; de < top; de = ext3_next_entry(de)) {
1141 + ext3fs_dirhash(de->name, de->name_len, &hinfo);
1142 + if ((hinfo.hash < start_hash) ||
1143 + ((hinfo.hash == start_hash) &&
1144 + (hinfo.minor_hash < start_minor_hash)))
1146 + if ((err = ext3_htree_store_dirent(dir_file,
1147 + hinfo.hash, hinfo.minor_hash, de)) != 0)
1153 + ret = ext3_htree_next_block(dir, HASH_NB_ALWAYS,
1154 + frame, frames, &err, &hashval);
1156 + *next_hash = hashval;
1160 + * Stop if: (a) there are no more entries, or
1161 + * (b) we have inserted at least one entry and the
1162 + * next hash value is not a continuation
1165 + (count && ((hashval & 1) == 0)))
1168 + dx_release(frames);
1169 + dxtrace(printk("Fill tree: returned %d entries\n", count));
1172 + dx_release(frames);
1178 + * Directory block splitting, compacting
1181 +static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
1182 + struct dx_hash_info *hinfo, struct dx_map_entry *map_tail)
1185 + char *base = (char *) de;
1186 + struct dx_hash_info h = *hinfo;
1188 + while ((char *) de < base + size)
1190 + if (de->name_len && de->inode) {
1191 + ext3fs_dirhash(de->name, de->name_len, &h);
1193 + map_tail->hash = h.hash;
1194 + map_tail->offs = (u32) ((char *) de - base);
1197 + /* XXX: do we need to check rec_len == 0 case? -Chris */
1198 + de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
1203 +static void dx_sort_map (struct dx_map_entry *map, unsigned count)
1205 + struct dx_map_entry *p, *q, *top = map + count - 1;
1207 + /* Combsort until bubble sort doesn't suck */
1210 + count = count*10/13;
1211 + if (count - 9 < 2) /* 9, 10 -> 11 */
1213 + for (p = top, q = p - count; q >= map; p--, q--)
1214 + if (p->hash < q->hash)
1217 + /* Garden variety bubble sort */
1223 + if (q[1].hash >= q[0].hash)
1231 +static void dx_insert_block(struct dx_frame *frame, u32 hash, u32 block)
1233 + struct dx_entry *entries = frame->entries;
1234 + struct dx_entry *old = frame->at, *new = old + 1;
1235 + int count = dx_get_count(entries);
1237 + assert(count < dx_get_limit(entries));
1238 + assert(old < entries + count);
1239 + memmove(new + 1, new, (char *)(entries + count) - (char *)(new));
1240 + dx_set_hash(new, hash);
1241 + dx_set_block(new, block);
1242 + dx_set_count(entries, count + 1);
1247 +static void ext3_update_dx_flag(struct inode *inode)
1249 + if (!EXT3_HAS_COMPAT_FEATURE(inode->i_sb,
1250 + EXT3_FEATURE_COMPAT_DIR_INDEX))
1251 + EXT3_I(inode)->i_flags &= ~EXT3_INDEX_FL;
1255 * NOTE! unlike strncmp, ext3_match returns 1 for success, 0 for failure.
1266 * The returned buffer_head has ->b_count elevated. The caller is expected
1267 * to brelse() it when appropriate.
1271 static struct buffer_head * ext3_find_entry (struct dentry *dentry,
1272 struct ext3_dir_entry_2 ** res_dir)
1274 @@ -119,12 +764,32 @@
1276 int nblocks, i, err;
1277 struct inode *dir = dentry->d_parent->d_inode;
1280 + unsigned blocksize;
1285 + blocksize = sb->s_blocksize;
1286 + namelen = dentry->d_name.len;
1287 + name = dentry->d_name.name;
1288 + if (namelen > EXT3_NAME_LEN)
1290 +#ifdef CONFIG_EXT3_INDEX
1292 + bh = ext3_dx_find_entry(dentry, res_dir, &err);
1294 + * On success, or if the error was file not found,
1295 + * return. Otherwise, fall back to doing a search the
1296 + * old fashioned way.
1298 + if (bh || (err != ERR_BAD_DX_DIR))
1300 + dxtrace(printk("ext3_find_entry: dx failed, falling back\n"));
1303 nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb);
1304 - start = dir->u.ext3_i.i_dir_start_lookup;
1305 + start = EXT3_I(dir)->i_dir_start_lookup;
1306 if (start >= nblocks)
1310 i = search_dirblock(bh, dir, dentry,
1311 block << EXT3_BLOCK_SIZE_BITS(sb), res_dir);
1313 - dir->u.ext3_i.i_dir_start_lookup = block;
1314 + EXT3_I(dir)->i_dir_start_lookup = block;
1316 goto cleanup_and_exit;
1318 @@ -196,6 +861,66 @@
1322 +#ifdef CONFIG_EXT3_INDEX
1323 +static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
1324 + struct ext3_dir_entry_2 **res_dir, int *err)
1326 + struct super_block * sb;
1327 + struct dx_hash_info hinfo;
1329 + struct dx_frame frames[2], *frame;
1330 + struct ext3_dir_entry_2 *de, *top;
1331 + struct buffer_head *bh;
1332 + unsigned long block;
1334 + int namelen = dentry->d_name.len;
1335 + const u8 *name = dentry->d_name.name;
1336 + struct inode *dir = dentry->d_parent->d_inode;
1339 + if (!(frame = dx_probe (dentry, 0, &hinfo, frames, err)))
1341 + hash = hinfo.hash;
1343 + block = dx_get_block(frame->at);
1344 + if (!(bh = ext3_bread (NULL,dir, block, 0, err)))
1346 + de = (struct ext3_dir_entry_2 *) bh->b_data;
1347 + top = (struct ext3_dir_entry_2 *) ((char *) de + sb->s_blocksize -
1348 + EXT3_DIR_REC_LEN(0));
1349 + for (; de < top; de = ext3_next_entry(de))
1350 + if (ext3_match (namelen, name, de)) {
1351 + if (!ext3_check_dir_entry("ext3_find_entry",
1353 + (block<<EXT3_BLOCK_SIZE_BITS(sb))
1354 + +((char *)de - bh->b_data))) {
1359 + dx_release (frames);
1363 + /* Check to see if we should continue to search */
1364 + retval = ext3_htree_next_block(dir, hash, frame,
1366 + if (retval == -1) {
1367 + ext3_warning(sb, __FUNCTION__,
1368 + "error reading index page in directory #%lu",
1372 + } while (retval == 1);
1376 + dxtrace(printk("%s not found\n", name));
1377 + dx_release (frames);
1382 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
1384 struct inode * inode;
1387 inode = iget(dir->i_sb, ino);
1391 return ERR_PTR(-EACCES);
1394 d_add(dentry, inode);
1396 @@ -237,6 +963,301 @@
1397 de->file_type = ext3_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1400 +#ifdef CONFIG_EXT3_INDEX
1401 +static struct ext3_dir_entry_2 *
1402 +dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count)
1404 + unsigned rec_len = 0;
1407 + struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) (from + map->offs);
1408 + rec_len = EXT3_DIR_REC_LEN(de->name_len);
1409 + memcpy (to, de, rec_len);
1410 + ((struct ext3_dir_entry_2 *)to)->rec_len = cpu_to_le16(rec_len);
1415 + return (struct ext3_dir_entry_2 *) (to - rec_len);
1418 +static struct ext3_dir_entry_2* dx_pack_dirents(char *base, int size)
1420 + struct ext3_dir_entry_2 *next, *to, *prev, *de = (struct ext3_dir_entry_2 *) base;
1421 + unsigned rec_len = 0;
1424 + while ((char*)de < base + size) {
1425 + next = (struct ext3_dir_entry_2 *) ((char *) de +
1426 + le16_to_cpu(de->rec_len));
1427 + if (de->inode && de->name_len) {
1428 + rec_len = EXT3_DIR_REC_LEN(de->name_len);
1430 + memmove(to, de, rec_len);
1431 + to->rec_len = cpu_to_le16(rec_len);
1433 + to = (struct ext3_dir_entry_2 *)((char *)to + rec_len);
1440 +static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1441 + struct buffer_head **bh,struct dx_frame *frame,
1442 + struct dx_hash_info *hinfo, int *error)
1444 + unsigned blocksize = dir->i_sb->s_blocksize;
1445 + unsigned count, continued;
1446 + struct buffer_head *bh2;
1449 + struct dx_map_entry *map;
1450 + char *data1 = (*bh)->b_data, *data2;
1452 + struct ext3_dir_entry_2 *de = NULL, *de2;
1455 + bh2 = ext3_append (handle, dir, &newblock, error);
1462 + BUFFER_TRACE(*bh, "get_write_access");
1463 + err = ext3_journal_get_write_access(handle, *bh);
1469 + ext3_std_error(dir->i_sb, err);
1472 + BUFFER_TRACE(frame->bh, "get_write_access");
1473 + err = ext3_journal_get_write_access(handle, frame->bh);
1475 + goto journal_error;
1477 + data2 = bh2->b_data;
1479 + /* create map in the end of data2 block */
1480 + map = (struct dx_map_entry *) (data2 + blocksize);
1481 + count = dx_make_map ((struct ext3_dir_entry_2 *) data1,
1482 + blocksize, hinfo, map);
1484 + split = count/2; // need to adjust to actual middle
1485 + dx_sort_map (map, count);
1486 + hash2 = map[split].hash;
1487 + continued = hash2 == map[split - 1].hash;
1488 + dxtrace(printk("Split block %i at %x, %i/%i\n",
1489 + dx_get_block(frame->at), hash2, split, count-split));
1491 + /* Fancy dance to stay within two buffers */
1492 + de2 = dx_move_dirents(data1, data2, map + split, count - split);
1493 + de = dx_pack_dirents(data1,blocksize);
1494 + de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
1495 + de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2);
1496 + dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data1, blocksize, 1));
1497 + dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data2, blocksize, 1));
1499 + /* Which block gets the new entry? */
1500 + if (hinfo->hash >= hash2)
1505 + dx_insert_block (frame, hash2 + continued, newblock);
1506 + err = ext3_journal_dirty_metadata (handle, bh2);
1508 + goto journal_error;
1509 + err = ext3_journal_dirty_metadata (handle, frame->bh);
1511 + goto journal_error;
1513 + dxtrace(dx_show_index ("frame", frame->entries));
1521 + * Add a new entry into a directory (leaf) block. If de is non-NULL,
1522 + * it points to a directory entry which is guaranteed to be large
1523 + * enough for new directory entry. If de is NULL, then
1524 + * add_dirent_to_buf will attempt search the directory block for
1525 + * space. It will return -ENOSPC if no space is available, and -EIO
1526 + * and -EEXIST if directory entry already exists.
1528 + * NOTE! bh is NOT released in the case where ENOSPC is returned. In
1529 + * all other cases bh is released.
1531 +static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1532 + struct inode *inode, struct ext3_dir_entry_2 *de,
1533 + struct buffer_head * bh)
1535 + struct inode *dir = dentry->d_parent->d_inode;
1536 + const char *name = dentry->d_name.name;
1537 + int namelen = dentry->d_name.len;
1538 + unsigned long offset = 0;
1539 + unsigned short reclen;
1540 + int nlen, rlen, err;
1543 + reclen = EXT3_DIR_REC_LEN(namelen);
1545 + de = (struct ext3_dir_entry_2 *)bh->b_data;
1546 + top = bh->b_data + dir->i_sb->s_blocksize - reclen;
1547 + while ((char *) de <= top) {
1548 + if (!ext3_check_dir_entry("ext3_add_entry", dir, de,
1553 + if (ext3_match (namelen, name, de)) {
1557 + nlen = EXT3_DIR_REC_LEN(de->name_len);
1558 + rlen = le16_to_cpu(de->rec_len);
1559 + if ((de->inode? rlen - nlen: rlen) >= reclen)
1561 + de = (struct ext3_dir_entry_2 *)((char *)de + rlen);
1564 + if ((char *) de > top)
1567 + BUFFER_TRACE(bh, "get_write_access");
1568 + err = ext3_journal_get_write_access(handle, bh);
1570 + ext3_std_error(dir->i_sb, err);
1575 + /* By now the buffer is marked for journaling */
1576 + nlen = EXT3_DIR_REC_LEN(de->name_len);
1577 + rlen = le16_to_cpu(de->rec_len);
1579 + struct ext3_dir_entry_2 *de1 = (struct ext3_dir_entry_2 *)((char *)de + nlen);
1580 + de1->rec_len = cpu_to_le16(rlen - nlen);
1581 + de->rec_len = cpu_to_le16(nlen);
1584 + de->file_type = EXT3_FT_UNKNOWN;
1586 + de->inode = cpu_to_le32(inode->i_ino);
1587 + ext3_set_de_type(dir->i_sb, de, inode->i_mode);
1590 + de->name_len = namelen;
1591 + memcpy (de->name, name, namelen);
1593 + * XXX shouldn't update any times until successful
1594 + * completion of syscall, but too many callers depend
1597 + * XXX similarly, too many callers depend on
1598 + * ext3_new_inode() setting the times, but error
1599 + * recovery deletes the inode, so the worst that can
1600 + * happen is that the times are slightly out of date
1601 + * and/or different from the directory change time.
1603 + dir->i_mtime = dir->i_ctime = CURRENT_TIME;
1604 + ext3_update_dx_flag(dir);
1605 + dir->i_version = ++event;
1606 + ext3_mark_inode_dirty(handle, dir);
1607 + BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
1608 + err = ext3_journal_dirty_metadata(handle, bh);
1610 + ext3_std_error(dir->i_sb, err);
1615 +#ifdef CONFIG_EXT3_INDEX
1617 + * This converts a one block unindexed directory to a 3 block indexed
1618 + * directory, and adds the dentry to the indexed directory.
1620 +static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1621 + struct inode *inode, struct buffer_head *bh)
1623 + struct inode *dir = dentry->d_parent->d_inode;
1624 + const char *name = dentry->d_name.name;
1625 + int namelen = dentry->d_name.len;
1626 + struct buffer_head *bh2;
1627 + struct dx_root *root;
1628 + struct dx_frame frames[2], *frame;
1629 + struct dx_entry *entries;
1630 + struct ext3_dir_entry_2 *de, *de2;
1631 + char *data1, *top;
1634 + unsigned blocksize;
1635 + struct dx_hash_info hinfo;
1638 + blocksize = dir->i_sb->s_blocksize;
1639 + dxtrace(printk("Creating index\n"));
1640 + retval = ext3_journal_get_write_access(handle, bh);
1642 + ext3_std_error(dir->i_sb, retval);
1646 + root = (struct dx_root *) bh->b_data;
1648 + EXT3_I(dir)->i_flags |= EXT3_INDEX_FL;
1649 + bh2 = ext3_append (handle, dir, &block, &retval);
1654 + data1 = bh2->b_data;
1656 + /* The 0th block becomes the root, move the dirents out */
1657 + de = (struct ext3_dir_entry_2 *)&root->dotdot;
1658 + de = (struct ext3_dir_entry_2 *)((char *)de + le16_to_cpu(de->rec_len));
1659 + len = ((char *) root) + blocksize - (char *) de;
1660 + memcpy (data1, de, len);
1661 + de = (struct ext3_dir_entry_2 *) data1;
1662 + top = data1 + len;
1663 + while (((char *) de2=(char*)de+le16_to_cpu(de->rec_len)) < top)
1665 + de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
1666 + /* Initialize the root; the dot dirents already exist */
1667 + de = (struct ext3_dir_entry_2 *) (&root->dotdot);
1668 + de->rec_len = cpu_to_le16(blocksize - EXT3_DIR_REC_LEN(2));
1669 + memset (&root->info, 0, sizeof(root->info));
1670 + root->info.info_length = sizeof(root->info);
1671 + root->info.hash_version = dir->i_sb->u.ext3_sb.s_def_hash_version;
1672 + entries = root->entries;
1673 + dx_set_block (entries, 1);
1674 + dx_set_count (entries, 1);
1675 + dx_set_limit (entries, dx_root_limit(dir, sizeof(root->info)));
1677 + /* Initialize as for dx_probe */
1678 + hinfo.hash_version = root->info.hash_version;
1679 + hinfo.seed = dir->i_sb->u.ext3_sb.s_hash_seed;
1680 + ext3fs_dirhash(name, namelen, &hinfo);
1682 + frame->entries = entries;
1683 + frame->at = entries;
1686 + de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1687 + dx_release (frames);
1691 + return add_dirent_to_buf(handle, dentry, inode, de, bh);
1698 @@ -247,127 +1268,198 @@
1699 * may not sleep between calling this and putting something into
1700 * the entry, as someone else might have used it while you slept.
1704 - * AKPM: the journalling code here looks wrong on the error paths
1706 static int ext3_add_entry (handle_t *handle, struct dentry *dentry,
1707 struct inode *inode)
1709 struct inode *dir = dentry->d_parent->d_inode;
1710 - const char *name = dentry->d_name.name;
1711 - int namelen = dentry->d_name.len;
1712 unsigned long offset;
1713 - unsigned short rec_len;
1714 struct buffer_head * bh;
1715 - struct ext3_dir_entry_2 * de, * de1;
1716 + struct ext3_dir_entry_2 *de;
1717 struct super_block * sb;
1719 +#ifdef CONFIG_EXT3_INDEX
1720 + int dx_fallback=0;
1722 + unsigned blocksize;
1723 + unsigned nlen, rlen;
1724 + u32 block, blocks;
1729 + blocksize = sb->s_blocksize;
1730 + if (!dentry->d_name.len)
1732 - bh = ext3_bread (handle, dir, 0, 0, &retval);
1733 +#ifdef CONFIG_EXT3_INDEX
1735 + retval = ext3_dx_add_entry(handle, dentry, inode);
1736 + if (!retval || (retval != ERR_BAD_DX_DIR))
1738 + EXT3_I(dir)->i_flags &= ~EXT3_INDEX_FL;
1740 + ext3_mark_inode_dirty(handle, dir);
1743 + blocks = dir->i_size >> sb->s_blocksize_bits;
1744 + for (block = 0, offset = 0; block < blocks; block++) {
1745 + bh = ext3_bread(handle, dir, block, 0, &retval);
1748 + retval = add_dirent_to_buf(handle, dentry, inode, 0, bh);
1749 + if (retval != -ENOSPC)
1752 +#ifdef CONFIG_EXT3_INDEX
1753 + if (blocks == 1 && !dx_fallback &&
1754 + EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX))
1755 + return make_indexed_dir(handle, dentry, inode, bh);
1759 + bh = ext3_append(handle, dir, &block, &retval);
1762 - rec_len = EXT3_DIR_REC_LEN(namelen);
1764 de = (struct ext3_dir_entry_2 *) bh->b_data;
1766 - if ((char *)de >= sb->s_blocksize + bh->b_data) {
1769 - bh = ext3_bread (handle, dir,
1770 - offset >> EXT3_BLOCK_SIZE_BITS(sb), 1, &retval);
1773 - if (dir->i_size <= offset) {
1774 - if (dir->i_size == 0) {
1779 + de->rec_len = cpu_to_le16(rlen = blocksize);
1781 + return add_dirent_to_buf(handle, dentry, inode, de, bh);
1784 - ext3_debug ("creating next block\n");
1785 +#ifdef CONFIG_EXT3_INDEX
1787 + * Returns 0 for success, or a negative error value
1789 +static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1790 + struct inode *inode)
1792 + struct dx_frame frames[2], *frame;
1793 + struct dx_entry *entries, *at;
1794 + struct dx_hash_info hinfo;
1795 + struct buffer_head * bh;
1796 + struct inode *dir = dentry->d_parent->d_inode;
1797 + struct super_block * sb = dir->i_sb;
1798 + struct ext3_dir_entry_2 *de;
1801 - BUFFER_TRACE(bh, "get_write_access");
1802 - ext3_journal_get_write_access(handle, bh);
1803 - de = (struct ext3_dir_entry_2 *) bh->b_data;
1805 - de->rec_len = le16_to_cpu(sb->s_blocksize);
1806 - dir->u.ext3_i.i_disksize =
1807 - dir->i_size = offset + sb->s_blocksize;
1808 - dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
1809 - ext3_mark_inode_dirty(handle, dir);
1811 + frame = dx_probe(dentry, 0, &hinfo, frames, &err);
1814 + entries = frame->entries;
1817 - ext3_debug ("skipping to next block\n");
1818 + if (!(bh = ext3_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
1821 - de = (struct ext3_dir_entry_2 *) bh->b_data;
1824 - if (!ext3_check_dir_entry ("ext3_add_entry", dir, de, bh,
1829 - if (ext3_match (namelen, name, de)) {
1832 + BUFFER_TRACE(bh, "get_write_access");
1833 + err = ext3_journal_get_write_access(handle, bh);
1835 + goto journal_error;
1837 + err = add_dirent_to_buf(handle, dentry, inode, 0, bh);
1838 + if (err != -ENOSPC) {
1843 + /* Block full, should compress but for now just split */
1844 + dxtrace(printk("using %u of %u node entries\n",
1845 + dx_get_count(entries), dx_get_limit(entries)));
1846 + /* Need to split index? */
1847 + if (dx_get_count(entries) == dx_get_limit(entries)) {
1849 + unsigned icount = dx_get_count(entries);
1850 + int levels = frame - frames;
1851 + struct dx_entry *entries2;
1852 + struct dx_node *node2;
1853 + struct buffer_head *bh2;
1855 + if (levels && (dx_get_count(frames->entries) ==
1856 + dx_get_limit(frames->entries))) {
1857 + ext3_warning(sb, __FUNCTION__,
1858 + "Directory index full!\n");
1862 - if ((le32_to_cpu(de->inode) == 0 &&
1863 - le16_to_cpu(de->rec_len) >= rec_len) ||
1864 - (le16_to_cpu(de->rec_len) >=
1865 - EXT3_DIR_REC_LEN(de->name_len) + rec_len)) {
1866 - BUFFER_TRACE(bh, "get_write_access");
1867 - ext3_journal_get_write_access(handle, bh);
1868 - /* By now the buffer is marked for journaling */
1869 - offset += le16_to_cpu(de->rec_len);
1870 - if (le32_to_cpu(de->inode)) {
1871 - de1 = (struct ext3_dir_entry_2 *) ((char *) de +
1872 - EXT3_DIR_REC_LEN(de->name_len));
1874 - cpu_to_le16(le16_to_cpu(de->rec_len) -
1875 - EXT3_DIR_REC_LEN(de->name_len));
1876 - de->rec_len = cpu_to_le16(
1877 - EXT3_DIR_REC_LEN(de->name_len));
1879 + bh2 = ext3_append (handle, dir, &newblock, &err);
1882 + node2 = (struct dx_node *)(bh2->b_data);
1883 + entries2 = node2->entries;
1884 + node2->fake.rec_len = cpu_to_le16(sb->s_blocksize);
1885 + node2->fake.inode = 0;
1886 + BUFFER_TRACE(frame->bh, "get_write_access");
1887 + err = ext3_journal_get_write_access(handle, frame->bh);
1889 + goto journal_error;
1891 + unsigned icount1 = icount/2, icount2 = icount - icount1;
1892 + unsigned hash2 = dx_get_hash(entries + icount1);
1893 + dxtrace(printk("Split index %i/%i\n", icount1, icount2));
1895 + BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
1896 + err = ext3_journal_get_write_access(handle,
1899 + goto journal_error;
1901 + memcpy ((char *) entries2, (char *) (entries + icount1),
1902 + icount2 * sizeof(struct dx_entry));
1903 + dx_set_count (entries, icount1);
1904 + dx_set_count (entries2, icount2);
1905 + dx_set_limit (entries2, dx_node_limit(dir));
1907 + /* Which index block gets the new entry? */
1908 + if (at - entries >= icount1) {
1909 + frame->at = at = at - entries - icount1 + entries2;
1910 + frame->entries = entries = entries2;
1911 + swap(frame->bh, bh2);
1913 - de->file_type = EXT3_FT_UNKNOWN;
1915 - de->inode = cpu_to_le32(inode->i_ino);
1916 - ext3_set_de_type(dir->i_sb, de, inode->i_mode);
1919 - de->name_len = namelen;
1920 - memcpy (de->name, name, namelen);
1922 - * XXX shouldn't update any times until successful
1923 - * completion of syscall, but too many callers depend
1926 - * XXX similarly, too many callers depend on
1927 - * ext3_new_inode() setting the times, but error
1928 - * recovery deletes the inode, so the worst that can
1929 - * happen is that the times are slightly out of date
1930 - * and/or different from the directory change time.
1932 - dir->i_mtime = dir->i_ctime = CURRENT_TIME;
1933 - dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
1934 - dir->i_version = ++event;
1935 - ext3_mark_inode_dirty(handle, dir);
1936 - BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
1937 - ext3_journal_dirty_metadata(handle, bh);
1940 + dx_insert_block (frames + 0, hash2, newblock);
1941 + dxtrace(dx_show_index ("node", frames[1].entries));
1942 + dxtrace(dx_show_index ("node",
1943 + ((struct dx_node *) bh2->b_data)->entries));
1944 + err = ext3_journal_dirty_metadata(handle, bh2);
1946 + goto journal_error;
1949 + dxtrace(printk("Creating second level index...\n"));
1950 + memcpy((char *) entries2, (char *) entries,
1951 + icount * sizeof(struct dx_entry));
1952 + dx_set_limit(entries2, dx_node_limit(dir));
1955 + dx_set_count(entries, 1);
1956 + dx_set_block(entries + 0, newblock);
1957 + ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
1959 + /* Add new access path frame */
1960 + frame = frames + 1;
1961 + frame->at = at = at - entries + entries2;
1962 + frame->entries = entries = entries2;
1964 + err = ext3_journal_get_write_access(handle,
1967 + goto journal_error;
1969 - offset += le16_to_cpu(de->rec_len);
1970 - de = (struct ext3_dir_entry_2 *)
1971 - ((char *) de + le16_to_cpu(de->rec_len));
1972 + ext3_journal_dirty_metadata(handle, frames[0].bh);
1976 + de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1979 + err = add_dirent_to_buf(handle, dentry, inode, de, bh);
1984 + ext3_std_error(dir->i_sb, err);
1988 + dx_release(frames);
1994 * ext3_delete_entry deletes a directory entry by merging it with the
1995 @@ -454,9 +1546,11 @@
1996 struct inode * inode;
1999 - handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + 3);
2000 - if (IS_ERR(handle))
2001 + handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
2002 + EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3);
2003 + if (IS_ERR(handle)) {
2004 return PTR_ERR(handle);
2009 @@ -480,9 +1574,11 @@
2010 struct inode *inode;
2013 - handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + 3);
2014 - if (IS_ERR(handle))
2015 + handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
2016 + EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3);
2017 + if (IS_ERR(handle)) {
2018 return PTR_ERR(handle);
2023 @@ -508,9 +1604,11 @@
2024 if (dir->i_nlink >= EXT3_LINK_MAX)
2027 - handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + 3);
2028 - if (IS_ERR(handle))
2029 + handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
2030 + EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3);
2031 + if (IS_ERR(handle)) {
2032 return PTR_ERR(handle);
2037 @@ -522,7 +1620,7 @@
2039 inode->i_op = &ext3_dir_inode_operations;
2040 inode->i_fop = &ext3_dir_operations;
2041 - inode->i_size = inode->u.ext3_i.i_disksize = inode->i_sb->s_blocksize;
2042 + inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
2043 inode->i_blocks = 0;
2044 dir_block = ext3_bread (handle, inode, 0, 1, &err);
2046 @@ -555,21 +1653,19 @@
2047 inode->i_mode |= S_ISGID;
2048 ext3_mark_inode_dirty(handle, inode);
2049 err = ext3_add_entry (handle, dentry, inode);
2051 - goto out_no_entry;
2053 + inode->i_nlink = 0;
2054 + ext3_mark_inode_dirty(handle, inode);
2059 - dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
2060 + ext3_update_dx_flag(dir);
2061 ext3_mark_inode_dirty(handle, dir);
2062 d_instantiate(dentry, inode);
2064 ext3_journal_stop(handle, dir);
2068 - inode->i_nlink = 0;
2069 - ext3_mark_inode_dirty(handle, inode);
2075 @@ -656,7 +1752,7 @@
2079 - if (!list_empty(&inode->u.ext3_i.i_orphan))
2080 + if (!list_empty(&EXT3_I(inode)->i_orphan))
2083 /* Orphan handling is only valid for files with data blocks
2084 @@ -697,7 +1793,7 @@
2085 * This is safe: on error we're going to ignore the orphan list
2086 * anyway on the next recovery. */
2088 - list_add(&inode->u.ext3_i.i_orphan, &EXT3_SB(sb)->s_orphan);
2089 + list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
2091 jbd_debug(4, "superblock will point to %ld\n", inode->i_ino);
2092 jbd_debug(4, "orphan inode %ld will point to %d\n",
2093 @@ -715,25 +1811,26 @@
2094 int ext3_orphan_del(handle_t *handle, struct inode *inode)
2096 struct list_head *prev;
2097 + struct ext3_inode_info *ei = EXT3_I(inode);
2098 struct ext3_sb_info *sbi;
2099 unsigned long ino_next;
2100 struct ext3_iloc iloc;
2103 lock_super(inode->i_sb);
2104 - if (list_empty(&inode->u.ext3_i.i_orphan)) {
2105 + if (list_empty(&ei->i_orphan)) {
2106 unlock_super(inode->i_sb);
2110 ino_next = NEXT_ORPHAN(inode);
2111 - prev = inode->u.ext3_i.i_orphan.prev;
2112 + prev = ei->i_orphan.prev;
2113 sbi = EXT3_SB(inode->i_sb);
2115 jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
2117 - list_del(&inode->u.ext3_i.i_orphan);
2118 - INIT_LIST_HEAD(&inode->u.ext3_i.i_orphan);
2119 + list_del(&ei->i_orphan);
2120 + INIT_LIST_HEAD(&ei->i_orphan);
2122 /* If we're on an error path, we may not have a valid
2123 * transaction handle with which to update the orphan list on
2124 @@ -794,8 +1891,9 @@
2127 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS);
2128 - if (IS_ERR(handle))
2129 + if (IS_ERR(handle)) {
2130 return PTR_ERR(handle);
2134 bh = ext3_find_entry (dentry, &de);
2135 @@ -833,7 +1931,7 @@
2137 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
2138 ext3_mark_inode_dirty(handle, inode);
2139 - dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
2140 + ext3_update_dx_flag(dir);
2141 ext3_mark_inode_dirty(handle, dir);
2144 @@ -851,8 +1949,9 @@
2147 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS);
2148 - if (IS_ERR(handle))
2149 + if (IS_ERR(handle)) {
2150 return PTR_ERR(handle);
2155 @@ -879,7 +1978,7 @@
2158 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
2159 - dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
2160 + ext3_update_dx_flag(dir);
2161 ext3_mark_inode_dirty(handle, dir);
2163 if (!inode->i_nlink)
2164 @@ -905,9 +2004,11 @@
2165 if (l > dir->i_sb->s_blocksize)
2166 return -ENAMETOOLONG;
2168 - handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + 5);
2169 - if (IS_ERR(handle))
2170 + handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
2171 + EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5);
2172 + if (IS_ERR(handle)) {
2173 return PTR_ERR(handle);
2178 @@ -917,7 +2018,7 @@
2182 - if (l > sizeof (inode->u.ext3_i.i_data)) {
2183 + if (l > sizeof (EXT3_I(inode)->i_data)) {
2184 inode->i_op = &page_symlink_inode_operations;
2185 inode->i_mapping->a_ops = &ext3_aops;
2187 @@ -926,24 +2027,22 @@
2188 * i_size in generic_commit_write().
2190 err = block_symlink(inode, symname, l);
2192 - goto out_no_entry;
2194 + ext3_dec_count(handle, inode);
2195 + ext3_mark_inode_dirty(handle, inode);
2200 inode->i_op = &ext3_fast_symlink_inode_operations;
2201 - memcpy((char*)&inode->u.ext3_i.i_data,symname,l);
2202 + memcpy((char*)&EXT3_I(inode)->i_data,symname,l);
2203 inode->i_size = l-1;
2205 - inode->u.ext3_i.i_disksize = inode->i_size;
2206 + EXT3_I(inode)->i_disksize = inode->i_size;
2207 err = ext3_add_nondir(handle, dentry, inode);
2209 ext3_journal_stop(handle, dir);
2213 - ext3_dec_count(handle, inode);
2214 - ext3_mark_inode_dirty(handle, inode);
2219 static int ext3_link (struct dentry * old_dentry,
2220 @@ -956,12 +2055,15 @@
2221 if (S_ISDIR(inode->i_mode))
2224 - if (inode->i_nlink >= EXT3_LINK_MAX)
2225 + if (inode->i_nlink >= EXT3_LINK_MAX) {
2229 - handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS);
2230 - if (IS_ERR(handle))
2231 + handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
2232 + EXT3_INDEX_EXTRA_TRANS_BLOCKS);
2233 + if (IS_ERR(handle)) {
2234 return PTR_ERR(handle);
2239 @@ -994,9 +2096,11 @@
2241 old_bh = new_bh = dir_bh = NULL;
2243 - handle = ext3_journal_start(old_dir, 2 * EXT3_DATA_TRANS_BLOCKS + 2);
2244 - if (IS_ERR(handle))
2245 + handle = ext3_journal_start(old_dir, 2 * EXT3_DATA_TRANS_BLOCKS +
2246 + EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2);
2247 + if (IS_ERR(handle)) {
2248 return PTR_ERR(handle);
2251 if (IS_SYNC(old_dir) || IS_SYNC(new_dir))
2253 @@ -1069,14 +2173,37 @@
2257 - ext3_delete_entry(handle, old_dir, old_de, old_bh);
2258 + if (le32_to_cpu(old_de->inode) != old_inode->i_ino ||
2259 + old_de->name_len != old_dentry->d_name.len ||
2260 + strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) ||
2261 + (retval = ext3_delete_entry(handle, old_dir,
2262 + old_de, old_bh)) == -ENOENT) {
2263 + /* old_de could have moved from under us during htree split, so
2264 + * make sure that we are deleting the right entry. We might
2265 + * also be pointing to a stale entry in the unused part of
2266 + * old_bh so just checking inum and the name isn't enough. */
2267 + struct buffer_head *old_bh2;
2268 + struct ext3_dir_entry_2 *old_de2;
2270 + old_bh2 = ext3_find_entry(old_dentry, &old_de2);
2272 + retval = ext3_delete_entry(handle, old_dir,
2273 + old_de2, old_bh2);
2278 + ext3_warning(old_dir->i_sb, "ext3_rename",
2279 + "Deleting old file (%lu), %d, error=%d",
2280 + old_dir->i_ino, old_dir->i_nlink, retval);
2284 new_inode->i_nlink--;
2285 new_inode->i_ctime = CURRENT_TIME;
2287 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
2288 - old_dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
2289 + ext3_update_dx_flag(old_dir);
2291 BUFFER_TRACE(dir_bh, "get_write_access");
2292 ext3_journal_get_write_access(handle, dir_bh);
2293 @@ -1088,7 +2215,7 @@
2294 new_inode->i_nlink--;
2297 - new_dir->u.ext3_i.i_flags &= ~EXT3_INDEX_FL;
2298 + ext3_update_dx_flag(new_dir);
2299 ext3_mark_inode_dirty(handle, new_dir);
2302 Index: linux-2.4.29/fs/ext3/super.c
2303 ===================================================================
2304 --- linux-2.4.29.orig/fs/ext3/super.c 2005-04-07 18:59:19.000000000 +0300
2305 +++ linux-2.4.29/fs/ext3/super.c 2005-05-03 16:29:50.580498544 +0300
2307 es->s_mtime = cpu_to_le32(CURRENT_TIME);
2308 ext3_update_dynamic_rev(sb);
2309 EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
2311 ext3_commit_super (sb, es, 1);
2312 if (test_opt (sb, DEBUG))
2315 EXT3_BLOCKS_PER_GROUP(sb),
2316 EXT3_INODES_PER_GROUP(sb),
2319 printk(KERN_INFO "EXT3 FS " EXT3FS_VERSION ", " EXT3FS_DATE " on %s, ",
2320 bdevname(sb->s_dev));
2321 if (EXT3_SB(sb)->s_journal->j_inode == NULL) {
2327 struct super_block * ext3_read_super (struct super_block * sb, void * data,
2330 @@ -1094,6 +1097,9 @@
2331 sbi->s_mount_state = le16_to_cpu(es->s_state);
2332 sbi->s_addr_per_block_bits = log2(EXT3_ADDR_PER_BLOCK(sb));
2333 sbi->s_desc_per_block_bits = log2(EXT3_DESC_PER_BLOCK(sb));
2334 + for (i=0; i < 4; i++)
2335 + sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
2336 + sbi->s_def_hash_version = es->s_def_hash_version;
2338 if (sbi->s_blocks_per_group > blocksize * 8) {
2340 @@ -1845,6 +1851,7 @@
2341 unregister_filesystem(&ext3_fs_type);
2344 +EXPORT_SYMBOL(ext3_force_commit);
2345 EXPORT_SYMBOL(ext3_bread);
2347 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2348 Index: linux-2.4.29/include/linux/ext3_fs.h
2349 ===================================================================
2350 --- linux-2.4.29.orig/include/linux/ext3_fs.h 2005-04-07 18:52:26.000000000 +0300
2351 +++ linux-2.4.29/include/linux/ext3_fs.h 2005-05-03 16:29:50.584497936 +0300
2353 #define EXT3FS_VERSION "2.4-0.9.19"
2356 + * Always enable hashed directories
2358 +#define CONFIG_EXT3_INDEX
2364 @@ -593,9 +598,46 @@
2365 #define EXT3_DIR_ROUND (EXT3_DIR_PAD - 1)
2366 #define EXT3_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT3_DIR_ROUND) & \
2369 + * Hash Tree Directory indexing
2370 + * (c) Daniel Phillips, 2001
2373 +#ifdef CONFIG_EXT3_INDEX
2374 + #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
2375 + EXT3_FEATURE_COMPAT_DIR_INDEX) && \
2376 + (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
2377 +#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
2378 +#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
2380 + #define is_dx(dir) 0
2381 +#define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX)
2382 +#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
2385 +/* Legal values for the dx_root hash_version field: */
2387 +#define DX_HASH_LEGACY 0
2388 +#define DX_HASH_HALF_MD4 1
2389 +#define DX_HASH_TEA 2
2391 +/* hash info structure used by the directory hash */
2392 +struct dx_hash_info
2402 + * Control parameters used by ext3_htree_next_block
2404 +#define HASH_NB_ALWAYS 1
2408 * Describe an inode's exact location on disk and in memory
2411 @@ -605,6 +647,27 @@
2412 unsigned long block_group;
2417 + * This structure is stuffed into the struct file's private_data field
2418 + * for directories. It is where we put information so that we can do
2419 + * readdir operations in hash tree order.
2421 +struct dir_private_info {
2423 + rb_node_t *curr_node;
2424 + struct fname *extra_fname;
2427 + __u32 curr_minor_hash;
2432 + * Special error return code only used by dx_probe() and its callers.
2434 +#define ERR_BAD_DX_DIR -75000
2437 * Function prototypes
2439 @@ -632,11 +695,20 @@
2442 extern int ext3_check_dir_entry(const char *, struct inode *,
2443 - struct ext3_dir_entry_2 *, struct buffer_head *,
2445 + struct ext3_dir_entry_2 *,
2446 + struct buffer_head *, unsigned long);
2447 +extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
2449 + struct ext3_dir_entry_2 *dirent);
2450 +extern void ext3_htree_free_dir_info(struct dir_private_info *p);
2453 extern int ext3_sync_file (struct file *, struct dentry *, int);
2456 +extern int ext3fs_dirhash(const char *name, int len, struct
2457 + dx_hash_info *hinfo);
2460 extern struct inode * ext3_new_inode (handle_t *, const struct inode *, int);
2461 extern void ext3_free_inode (handle_t *, struct inode *);
2464 extern int ext3_orphan_add(handle_t *, struct inode *);
2465 extern int ext3_orphan_del(handle_t *, struct inode *);
2466 +extern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
2467 + __u32 start_minor_hash, __u32 *next_hash);
2470 extern void ext3_error (struct super_block *, const char *, const char *, ...)
2471 Index: linux-2.4.29/include/linux/ext3_fs_sb.h
2472 ===================================================================
2473 --- linux-2.4.29.orig/include/linux/ext3_fs_sb.h 2005-04-07 18:54:55.000000000 +0300
2474 +++ linux-2.4.29/include/linux/ext3_fs_sb.h 2005-05-03 16:29:50.586497632 +0300
2478 u32 s_next_generation;
2479 + u32 s_hash_seed[4];
2480 + int s_def_hash_version;
2483 struct inode * s_journal_inode;
2484 Index: linux-2.4.29/include/linux/ext3_jbd.h
2485 ===================================================================
2486 --- linux-2.4.29.orig/include/linux/ext3_jbd.h 2005-04-07 18:52:32.000000000 +0300
2487 +++ linux-2.4.29/include/linux/ext3_jbd.h 2005-05-03 16:29:50.587497480 +0300
2490 #define EXT3_RESERVE_TRANS_BLOCKS 12U
2492 +#define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8
2495 ext3_mark_iloc_dirty(handle_t *handle,
2496 struct inode *inode,