[readdir] convert hfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2013-05-22 14:29:35 -04:00
parent f0f49ef5ce
commit 002f8bec85
1 changed files with 23 additions and 26 deletions

View File

@ -51,9 +51,9 @@ done:
/* /*
* hfs_readdir * hfs_readdir
*/ */
static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) static int hfs_readdir(struct file *file, struct dir_context *ctx)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(file);
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int len, err; int len, err;
char strbuf[HFS_MAX_NAMELEN]; char strbuf[HFS_MAX_NAMELEN];
@ -62,7 +62,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
struct hfs_readdir_data *rd; struct hfs_readdir_data *rd;
u16 type; u16 type;
if (filp->f_pos >= inode->i_size) if (ctx->pos >= inode->i_size)
return 0; return 0;
err = hfs_find_init(HFS_SB(sb)->cat_tree, &fd); err = hfs_find_init(HFS_SB(sb)->cat_tree, &fd);
@ -73,14 +73,13 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (err) if (err)
goto out; goto out;
switch ((u32)filp->f_pos) { if (ctx->pos == 0) {
case 0:
/* This is completely artificial... */ /* This is completely artificial... */
if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR)) if (!dir_emit_dot(file, ctx))
goto out; goto out;
filp->f_pos++; ctx->pos = 1;
/* fall through */ }
case 1: if (ctx->pos == 1) {
if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) {
err = -EIO; err = -EIO;
goto out; goto out;
@ -97,18 +96,16 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
// err = -EIO; // err = -EIO;
// goto out; // goto out;
//} //}
if (filldir(dirent, "..", 2, 1, if (!dir_emit(ctx, "..", 2,
be32_to_cpu(entry.thread.ParID), DT_DIR)) be32_to_cpu(entry.thread.ParID), DT_DIR))
goto out; goto out;
filp->f_pos++; ctx->pos = 2;
/* fall through */
default:
if (filp->f_pos >= inode->i_size)
goto out;
err = hfs_brec_goto(&fd, filp->f_pos - 1);
if (err)
goto out;
} }
if (ctx->pos >= inode->i_size)
goto out;
err = hfs_brec_goto(&fd, ctx->pos - 1);
if (err)
goto out;
for (;;) { for (;;) {
if (be32_to_cpu(fd.key->cat.ParID) != inode->i_ino) { if (be32_to_cpu(fd.key->cat.ParID) != inode->i_ino) {
@ -131,7 +128,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
err = -EIO; err = -EIO;
goto out; goto out;
} }
if (filldir(dirent, strbuf, len, filp->f_pos, if (!dir_emit(ctx, strbuf, len,
be32_to_cpu(entry.dir.DirID), DT_DIR)) be32_to_cpu(entry.dir.DirID), DT_DIR))
break; break;
} else if (type == HFS_CDR_FIL) { } else if (type == HFS_CDR_FIL) {
@ -140,7 +137,7 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
err = -EIO; err = -EIO;
goto out; goto out;
} }
if (filldir(dirent, strbuf, len, filp->f_pos, if (!dir_emit(ctx, strbuf, len,
be32_to_cpu(entry.file.FlNum), DT_REG)) be32_to_cpu(entry.file.FlNum), DT_REG))
break; break;
} else { } else {
@ -148,22 +145,22 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
err = -EIO; err = -EIO;
goto out; goto out;
} }
filp->f_pos++; ctx->pos++;
if (filp->f_pos >= inode->i_size) if (ctx->pos >= inode->i_size)
goto out; goto out;
err = hfs_brec_goto(&fd, 1); err = hfs_brec_goto(&fd, 1);
if (err) if (err)
goto out; goto out;
} }
rd = filp->private_data; rd = file->private_data;
if (!rd) { if (!rd) {
rd = kmalloc(sizeof(struct hfs_readdir_data), GFP_KERNEL); rd = kmalloc(sizeof(struct hfs_readdir_data), GFP_KERNEL);
if (!rd) { if (!rd) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
filp->private_data = rd; file->private_data = rd;
rd->file = filp; rd->file = file;
list_add(&rd->list, &HFS_I(inode)->open_dir_list); list_add(&rd->list, &HFS_I(inode)->open_dir_list);
} }
memcpy(&rd->key, &fd.key, sizeof(struct hfs_cat_key)); memcpy(&rd->key, &fd.key, sizeof(struct hfs_cat_key));
@ -306,7 +303,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
const struct file_operations hfs_dir_operations = { const struct file_operations hfs_dir_operations = {
.read = generic_read_dir, .read = generic_read_dir,
.readdir = hfs_readdir, .iterate = hfs_readdir,
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.release = hfs_dir_release, .release = hfs_dir_release,
}; };