1 diff -r -u linux-stage.orig/fs/ext4/namei.c linux-stage/fs/ext4/namei.c
2 --- linux-stage.orig/fs/ext4/namei.c 2012-12-31 15:03:28.000000000 -0500
3 +++ linux-stage/fs/ext4/namei.c 2012-12-31 15:06:16.000000000 -0500
5 * hash version mod 4 should never be 0. Sincerely, the paranoia department.
11 - struct fake_dirent dot;
13 - struct fake_dirent dotdot;
14 - char dotdot_name[4];
17 - __le32 reserved_zero;
19 - u8 info_length; /* 8 */
24 - struct dx_entry entries[0];
25 + __le32 reserved_zero;
27 + u8 info_length; /* 8 */
34 * Future: use high four bits of block for coalesce-on-delete flags
35 * Mask them off for now.
37 +struct dx_root_info * dx_get_dx_info(struct ext4_dir_entry_2 *de)
39 + /* get dotdot first */
40 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
42 + /* dx root info is after dotdot entry */
43 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
45 + return (struct dx_root_info *) de;
48 static inline ext4_lblk_t dx_get_block(struct dx_entry *entry)
52 unsigned count, indirect;
53 struct dx_entry *at, *entries, *p, *q, *m;
54 - struct dx_root *root;
55 + struct dx_root_info * info;
56 struct buffer_head *bh;
57 struct dx_frame *frame = frame_in;
61 if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
63 - root = (struct dx_root *) bh->b_data;
64 - if (root->info.hash_version != DX_HASH_TEA &&
65 - root->info.hash_version != DX_HASH_HALF_MD4 &&
66 - root->info.hash_version != DX_HASH_LEGACY) {
68 + info = dx_get_dx_info((struct ext4_dir_entry_2*)bh->b_data);
69 + if (info->hash_version != DX_HASH_TEA &&
70 + info->hash_version != DX_HASH_HALF_MD4 &&
71 + info->hash_version != DX_HASH_LEGACY) {
72 ext4_warning(dir->i_sb, "Unrecognised inode hash code %d for directory "
73 - "#%lu", root->info.hash_version, dir->i_ino);
74 + "#%lu", info->hash_version, dir->i_ino);
76 *err = ERR_BAD_DX_DIR;
79 - hinfo->hash_version = root->info.hash_version;
80 + hinfo->hash_version = info->hash_version;
81 if (hinfo->hash_version <= DX_HASH_TEA)
82 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
83 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
85 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
88 - if (root->info.unused_flags & 1) {
89 + if (info->unused_flags & 1) {
90 ext4_warning(dir->i_sb, "Unimplemented inode hash flags: %#06x",
91 - root->info.unused_flags);
92 + info->unused_flags);
94 *err = ERR_BAD_DX_DIR;
98 - if ((indirect = root->info.indirect_levels) > 1) {
99 + if ((indirect = info->indirect_levels) > 1) {
100 ext4_warning(dir->i_sb, "Unimplemented inode hash depth: %#06x",
101 - root->info.indirect_levels);
102 + info->indirect_levels);
104 *err = ERR_BAD_DX_DIR;
108 - entries = (struct dx_entry *) (((char *)&root->info) +
109 - root->info.info_length);
110 + entries = (struct dx_entry *) (((char *)info) + info->info_length);
112 if (dx_get_limit(entries) != dx_root_limit(dir,
113 - root->info.info_length)) {
114 + info->info_length)) {
115 ext4_warning(dir->i_sb, "dx entry: limit != root limit");
117 *err = ERR_BAD_DX_DIR;
118 @@ -501,10 +502,12 @@
120 static void dx_release (struct dx_frame *frames)
122 + struct dx_root_info *info;
123 if (frames[0].bh == NULL)
126 - if (((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels)
127 + info = dx_get_dx_info((struct ext4_dir_entry_2*)frames[0].bh->b_data);
128 + if (info->indirect_levels)
129 brelse(frames[1].bh);
130 brelse(frames[0].bh);
132 @@ -1400,17 +1403,16 @@
133 const char *name = dentry->d_name.name;
134 int namelen = dentry->d_name.len;
135 struct buffer_head *bh2;
136 - struct dx_root *root;
137 struct dx_frame frames[2], *frame;
138 struct dx_entry *entries;
139 - struct ext4_dir_entry_2 *de, *de2;
140 + struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
145 struct dx_hash_info hinfo;
147 - struct fake_dirent *fde;
148 + struct dx_root_info *dx_info;
150 blocksize = dir->i_sb->s_blocksize;
151 dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino));
152 @@ -1420,18 +1422,19 @@
156 - root = (struct dx_root *) bh->b_data;
158 + dot_de = (struct ext4_dir_entry_2 *) bh->b_data;
159 + dotdot_de = ext4_next_entry(dot_de, blocksize);
161 /* The 0th block becomes the root, move the dirents out */
162 - fde = &root->dotdot;
163 - de = (struct ext4_dir_entry_2 *)((char *)fde +
164 - ext4_rec_len_from_disk(fde->rec_len, blocksize));
165 - if ((char *) de >= (((char *) root) + blocksize)) {
166 + de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
167 + ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
168 + if ((char *) de >= (((char *) dot_de) + blocksize)) {
169 EXT4_ERROR_INODE(dir, "invalid rec_len for '..'");
173 - len = ((char *) root) + blocksize - (char *) de;
174 + len = ((char *) dot_de) + blocksize - (char *) de;
176 /* Allocate new block for the 0th block's dirents */
177 bh2 = ext4_append(handle, dir, &block, &retval);
178 @@ -1450,19 +1453,23 @@
179 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de,
181 /* Initialize the root; the dot dirents already exist */
182 - de = (struct ext4_dir_entry_2 *) (&root->dotdot);
183 - de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
185 - memset (&root->info, 0, sizeof(root->info));
186 - root->info.info_length = sizeof(root->info);
187 - root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
188 - entries = root->entries;
189 + dotdot_de->rec_len = ext4_rec_len_to_disk(blocksize -
190 + le16_to_cpu(dot_de->rec_len), blocksize);
192 + /* initialize hashing info */
193 + dx_info = dx_get_dx_info(dot_de);
194 + memset (dx_info, 0, sizeof(*dx_info));
195 + dx_info->info_length = sizeof(*dx_info);
196 + dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
198 + entries = (void *)dx_info + sizeof(*dx_info);
200 dx_set_block(entries, 1);
201 dx_set_count(entries, 1);
202 - dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
203 + dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
205 /* Initialize as for dx_probe */
206 - hinfo.hash_version = root->info.hash_version;
207 + hinfo.hash_version = dx_info->hash_version;
208 if (hinfo.hash_version <= DX_HASH_TEA)
209 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
210 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
211 @@ -1723,6 +1730,7 @@
215 + struct dx_root_info * info;
216 dxtrace(printk(KERN_DEBUG
217 "Creating second level index...\n"));
218 memcpy((char *) entries2, (char *) entries,
219 @@ -1732,7 +1740,9 @@
221 dx_set_count(entries, 1);
222 dx_set_block(entries + 0, newblock);
223 - ((struct dx_root *) frames[0].bh->b_data)->info.indirect_levels = 1;
224 + info = dx_get_dx_info((struct ext4_dir_entry_2*)
225 + frames[0].bh->b_data);
226 + info->indirect_levels = 1;
228 /* Add new access path frame */