Commit 725bebb2 authored by Al Viro's avatar Al Viro

[readdir] convert ext4

and trim the living hell out bogosities in inline dir case
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4deb398a
This diff is collapsed.
...@@ -2515,7 +2515,7 @@ extern int ext4_try_create_inline_dir(handle_t *handle, ...@@ -2515,7 +2515,7 @@ extern int ext4_try_create_inline_dir(handle_t *handle,
struct inode *parent, struct inode *parent,
struct inode *inode); struct inode *inode);
extern int ext4_read_inline_dir(struct file *filp, extern int ext4_read_inline_dir(struct file *filp,
void *dirent, filldir_t filldir, struct dir_context *ctx,
int *has_inline_data); int *has_inline_data);
extern int htree_inlinedir_to_tree(struct file *dir_file, extern int htree_inlinedir_to_tree(struct file *dir_file,
struct inode *dir, ext4_lblk_t block, struct inode *dir, ext4_lblk_t block,
......
...@@ -1404,16 +1404,15 @@ int htree_inlinedir_to_tree(struct file *dir_file, ...@@ -1404,16 +1404,15 @@ int htree_inlinedir_to_tree(struct file *dir_file,
* offset as if '.' and '..' really take place. * offset as if '.' and '..' really take place.
* *
*/ */
int ext4_read_inline_dir(struct file *filp, int ext4_read_inline_dir(struct file *file,
void *dirent, filldir_t filldir, struct dir_context *ctx,
int *has_inline_data) int *has_inline_data)
{ {
int error = 0;
unsigned int offset, parent_ino; unsigned int offset, parent_ino;
int i, stored; int i;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct super_block *sb; struct super_block *sb;
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(file);
int ret, inline_size = 0; int ret, inline_size = 0;
struct ext4_iloc iloc; struct ext4_iloc iloc;
void *dir_buf = NULL; void *dir_buf = NULL;
...@@ -1444,9 +1443,8 @@ int ext4_read_inline_dir(struct file *filp, ...@@ -1444,9 +1443,8 @@ int ext4_read_inline_dir(struct file *filp,
goto out; goto out;
sb = inode->i_sb; sb = inode->i_sb;
stored = 0;
parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode); parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
offset = filp->f_pos; offset = ctx->pos;
/* /*
* dotdot_offset and dotdot_size is the real offset and * dotdot_offset and dotdot_size is the real offset and
...@@ -1460,15 +1458,13 @@ int ext4_read_inline_dir(struct file *filp, ...@@ -1460,15 +1458,13 @@ int ext4_read_inline_dir(struct file *filp,
extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE; extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
extra_size = extra_offset + inline_size; extra_size = extra_offset + inline_size;
while (!error && !stored && filp->f_pos < extra_size) {
revalidate:
/* /*
* If the version has changed since the last call to * If the version has changed since the last call to
* readdir(2), then we might be pointing to an invalid * readdir(2), then we might be pointing to an invalid
* dirent right now. Scan from the start of the inline * dirent right now. Scan from the start of the inline
* dir to make sure. * dir to make sure.
*/ */
if (filp->f_version != inode->i_version) { if (file->f_version != inode->i_version) {
for (i = 0; i < extra_size && i < offset;) { for (i = 0; i < extra_size && i < offset;) {
/* /*
* "." is with offset 0 and * "." is with offset 0 and
...@@ -1492,72 +1488,44 @@ int ext4_read_inline_dir(struct file *filp, ...@@ -1492,72 +1488,44 @@ int ext4_read_inline_dir(struct file *filp,
* least that it is non-zero. A * least that it is non-zero. A
* failure will be detected in the * failure will be detected in the
* dirent test below. */ * dirent test below. */
if (ext4_rec_len_from_disk(de->rec_len, if (ext4_rec_len_from_disk(de->rec_len, extra_size)
extra_size) < EXT4_DIR_REC_LEN(1)) < EXT4_DIR_REC_LEN(1))
break; break;
i += ext4_rec_len_from_disk(de->rec_len, i += ext4_rec_len_from_disk(de->rec_len,
extra_size); extra_size);
} }
offset = i; offset = i;
filp->f_pos = offset; ctx->pos = offset;
filp->f_version = inode->i_version; file->f_version = inode->i_version;
} }
while (!error && filp->f_pos < extra_size) { while (ctx->pos < extra_size) {
if (filp->f_pos == 0) { if (ctx->pos == 0) {
error = filldir(dirent, ".", 1, 0, inode->i_ino, if (!dir_emit(ctx, ".", 1, inode->i_ino, DT_DIR))
DT_DIR); goto out;
if (error) ctx->pos = dotdot_offset;
break;
stored++;
filp->f_pos = dotdot_offset;
continue; continue;
} }
if (filp->f_pos == dotdot_offset) { if (ctx->pos == dotdot_offset) {
error = filldir(dirent, "..", 2, if (!dir_emit(ctx, "..", 2, parent_ino, DT_DIR))
dotdot_offset, goto out;
parent_ino, DT_DIR); ctx->pos = dotdot_size;
if (error)
break;
stored++;
filp->f_pos = dotdot_size;
continue; continue;
} }
de = (struct ext4_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
(dir_buf + filp->f_pos - extra_offset); (dir_buf + ctx->pos - extra_offset);
if (ext4_check_dir_entry(inode, filp, de, if (ext4_check_dir_entry(inode, file, de, iloc.bh, dir_buf,
iloc.bh, dir_buf, extra_size, ctx->pos))
extra_size, filp->f_pos)) {
ret = stored;
goto out; goto out;
}
if (le32_to_cpu(de->inode)) { if (le32_to_cpu(de->inode)) {
/* We might block in the next section if (!dir_emit(ctx, de->name, de->name_len,
* if the data destination is
* currently swapped out. So, use a
* version stamp to detect whether or
* not the directory has been modified
* during the copy operation.
*/
u64 version = filp->f_version;
error = filldir(dirent, de->name,
de->name_len,
filp->f_pos,
le32_to_cpu(de->inode), le32_to_cpu(de->inode),
get_dtype(sb, de->file_type)); get_dtype(sb, de->file_type)))
if (error) goto out;
break;
if (version != filp->f_version)
goto revalidate;
stored++;
}
filp->f_pos += ext4_rec_len_from_disk(de->rec_len,
extra_size);
} }
ctx->pos += ext4_rec_len_from_disk(de->rec_len, extra_size);
} }
out: out:
kfree(dir_buf); kfree(dir_buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment