Skip to content

Commit

Permalink
[readdir] convert squashfs
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jun 29, 2013
1 parent 01122e0 commit 5f6039c
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions fs/squashfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int get_dir_index_using_offset(struct super_block *sb,
}


static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
static int squashfs_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *inode = file_inode(file);
struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
Expand All @@ -127,11 +127,11 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
* It also means that the external f_pos is offset by 3 from the
* on-disk directory f_pos.
*/
while (file->f_pos < 3) {
while (ctx->pos < 3) {
char *name;
int i_ino;

if (file->f_pos == 0) {
if (ctx->pos == 0) {
name = ".";
size = 1;
i_ino = inode->i_ino;
Expand All @@ -141,24 +141,18 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
i_ino = squashfs_i(inode)->parent;
}

TRACE("Calling filldir(%p, %s, %d, %lld, %d, %d)\n",
dirent, name, size, file->f_pos, i_ino,
squashfs_filetype_table[1]);

if (filldir(dirent, name, size, file->f_pos, i_ino,
squashfs_filetype_table[1]) < 0) {
TRACE("Filldir returned less than 0\n");
if (!dir_emit(ctx, name, size, i_ino,
squashfs_filetype_table[1]))
goto finish;
}

file->f_pos += size;
ctx->pos += size;
}

length = get_dir_index_using_offset(inode->i_sb, &block, &offset,
squashfs_i(inode)->dir_idx_start,
squashfs_i(inode)->dir_idx_offset,
squashfs_i(inode)->dir_idx_cnt,
file->f_pos);
ctx->pos);

while (length < i_size_read(inode)) {
/*
Expand Down Expand Up @@ -198,30 +192,20 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)

length += sizeof(*dire) + size;

if (file->f_pos >= length)
if (ctx->pos >= length)
continue;

dire->name[size] = '\0';
inode_number = le32_to_cpu(dirh.inode_number) +
((short) le16_to_cpu(dire->inode_number));
type = le16_to_cpu(dire->type);

TRACE("Calling filldir(%p, %s, %d, %lld, %x:%x, %d, %d)"
"\n", dirent, dire->name, size,
file->f_pos,
le32_to_cpu(dirh.start_block),
le16_to_cpu(dire->offset),
inode_number,
squashfs_filetype_table[type]);

if (filldir(dirent, dire->name, size, file->f_pos,
if (!dir_emit(ctx, dire->name, size,
inode_number,
squashfs_filetype_table[type]) < 0) {
TRACE("Filldir returned less than 0\n");
squashfs_filetype_table[type]))
goto finish;
}

file->f_pos = length;
ctx->pos = length;
}
}

Expand All @@ -238,6 +222,6 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)

const struct file_operations squashfs_dir_ops = {
.read = generic_read_dir,
.readdir = squashfs_readdir,
.iterate = squashfs_readdir,
.llseek = default_llseek,
};

0 comments on commit 5f6039c

Please sign in to comment.