27 static unsigned char ext3_filetype_table[] = {
31 static int ext3_dx_readdir(
struct file * filp,
34 static unsigned char get_dtype(
struct super_block *
sb,
int filetype)
40 return (ext3_filetype_table[filetype]);
65 struct buffer_head * bh,
68 const char * error_msg =
NULL;
69 const int rlen = ext3_rec_len_from_disk(de->
rec_len);
72 error_msg =
"rec_len is smaller than minimal";
74 error_msg =
"rec_len % 4 != 0";
76 error_msg =
"rec_len is too small for name_len";
77 else if (
unlikely((((
char *) de - bh->b_data) + rlen > dir->
i_sb->s_blocksize)))
78 error_msg =
"directory entry across blocks";
81 error_msg =
"inode out of bounds";
85 "bad entry in directory #%lu: %s - "
86 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
87 dir->
i_ino, error_msg, offset,
91 return error_msg ==
NULL ? 1 : 0;
94 static int ext3_readdir(
struct file * filp,
102 struct inode *inode = filp->
f_path.dentry->d_inode;
105 int dir_has_error = 0;
107 if (is_dx_dir(inode)) {
108 err = ext3_dx_readdir(filp, dirent, filldir);
117 EXT3_I(filp->
f_path.dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL;
122 while (!error && !stored && filp->
f_pos < inode->
i_size) {
124 struct buffer_head map_bh;
125 struct buffer_head *bh =
NULL;
132 if (!ra_has_index(&filp->
f_ra, index))
134 sb->
s_bdev->bd_inode->i_mapping,
146 if (!dir_has_error) {
148 "contains a hole at offset %lld",
174 if (ext3_rec_len_from_disk(de->
rec_len) <
177 i += ext3_rec_len_from_disk(de->
rec_len);
198 offset += ext3_rec_len_from_disk(de->
rec_len);
209 error = filldir(dirent, de->
name,
229 static inline int is_32bit_api(
void)
247 static inline loff_t hash2pos(
struct file *filp,
__u32 major,
__u32 minor)
253 return ((
__u64)(major >> 1) << 32) | (
__u64)minor;
256 static inline __u32 pos2maj_hash(
struct file *filp, loff_t
pos)
260 return (pos << 1) & 0xffffffff;
262 return ((pos >> 32) << 1) & 0xffffffff;
265 static inline __u32 pos2min_hash(
struct file *filp, loff_t pos)
271 return pos & 0xffffffff;
277 static inline loff_t ext3_get_htree_eof(
struct file *filp)
301 struct inode *inode = file->
f_mapping->host;
302 int dx_dir = is_dx_dir(inode);
303 loff_t htree_max = ext3_get_htree_eof(file);
307 htree_max, htree_max);
331 static void free_rb_tree_fname(
struct rb_root *root)
356 struct fname * old =
fname;
386 free_rb_tree_fname(&p->
root);
403 p = &info->
root.rb_node;
406 len =
sizeof(
struct fname) + dirent->
name_len + 1;
420 fname =
rb_entry(parent,
struct fname, rb_hash);
426 if ((new_fn->
hash == fname->
hash) &&
429 fname->
next = new_fn;
435 else if (new_fn->
hash > fname->
hash)
443 rb_link_node(&new_fn->
rb_hash, parent, p);
455 static int call_filldir(
struct file * filp,
void * dirent,
460 struct inode *inode = filp->
f_path.dentry->d_inode;
467 printk(
"call_filldir: called with null fname?!?\n");
472 error = filldir(dirent, fname->
name,
477 filp->
f_pos = curr_pos;
486 static int ext3_dx_readdir(
struct file * filp,
490 struct inode *inode = filp->
f_path.dentry->d_inode;
495 info = ext3_htree_create_dir_info(filp, filp->
f_pos);
501 if (filp->
f_pos == ext3_get_htree_eof(filp))
506 free_rb_tree_fname(&info->
root);
518 if (call_filldir(filp, dirent, filldir, info->
extra_fname))
534 free_rb_tree_fname(&info->
root);
542 filp->
f_pos = ext3_get_htree_eof(filp);
551 if (call_filldir(filp, dirent, filldir, fname))
562 filp->
f_pos = ext3_get_htree_eof(filp);
574 static int ext3_release_dir (
struct inode * inode,
struct file * filp)
585 .readdir = ext3_readdir,
591 .release = ext3_release_dir,