Skip to content

Commit

Permalink
[readdir] convert jfs
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Jun 29, 2013
1 parent 77acfa2 commit 070a0eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
63 changes: 29 additions & 34 deletions fs/jfs/jfs_dtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,9 +3002,9 @@ static inline struct jfs_dirent *next_jfs_dirent(struct jfs_dirent *dirent)
* return: offset = (pn, index) of start entry
* of next jfs_readdir()/dtRead()
*/
int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
int jfs_readdir(struct file *file, struct dir_context *ctx)
{
struct inode *ip = file_inode(filp);
struct inode *ip = file_inode(file);
struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab;
int rc = 0;
loff_t dtpos; /* legacy OS/2 style position */
Expand Down Expand Up @@ -3033,7 +3033,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
int overflow, fix_page, page_fixed = 0;
static int unique_pos = 2; /* If we can't fix broken index */

if (filp->f_pos == DIREND)
if (ctx->pos == DIREND)
return 0;

if (DO_INDEX(ip)) {
Expand All @@ -3045,33 +3045,33 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
*/
do_index = 1;

dir_index = (u32) filp->f_pos;
dir_index = (u32) ctx->pos;

if (dir_index > 1) {
struct dir_table_slot dirtab_slot;

if (dtEmpty(ip) ||
(dir_index >= JFS_IP(ip)->next_index)) {
/* Stale position. Directory has shrunk */
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
repeat:
rc = read_index(ip, dir_index, &dirtab_slot);
if (rc) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return rc;
}
if (dirtab_slot.flag == DIR_INDEX_FREE) {
if (loop_count++ > JFS_IP(ip)->next_index) {
jfs_err("jfs_readdir detected "
"infinite loop!");
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
dir_index = le32_to_cpu(dirtab_slot.addr2);
if (dir_index == -1) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
goto repeat;
Expand All @@ -3080,37 +3080,36 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
index = dirtab_slot.slot;
DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
if (rc) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
if (p->header.flag & BT_INTERNAL) {
jfs_err("jfs_readdir: bad index table");
DT_PUTPAGE(mp);
filp->f_pos = -1;
ctx->pos = -1;
return 0;
}
} else {
if (dir_index == 0) {
/*
* self "."
*/
filp->f_pos = 0;
if (filldir(dirent, ".", 1, 0, ip->i_ino,
DT_DIR))
ctx->pos = 0;
if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR))
return 0;
}
/*
* parent ".."
*/
filp->f_pos = 1;
if (filldir(dirent, "..", 2, 1, PARENT(ip), DT_DIR))
ctx->pos = 1;
if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR))
return 0;

/*
* Find first entry of left-most leaf
*/
if (dtEmpty(ip)) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}

Expand All @@ -3128,50 +3127,46 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
* pn > 0: Real entries, pn=1 -> leftmost page
* pn = index = -1: No more entries
*/
dtpos = filp->f_pos;
dtpos = ctx->pos;
if (dtpos == 0) {
/* build "." entry */

if (filldir(dirent, ".", 1, filp->f_pos, ip->i_ino,
DT_DIR))
if (!dir_emit(ctx, ".", 1, ip->i_ino, DT_DIR))
return 0;
dtoffset->index = 1;
filp->f_pos = dtpos;
ctx->pos = dtpos;
}

if (dtoffset->pn == 0) {
if (dtoffset->index == 1) {
/* build ".." entry */

if (filldir(dirent, "..", 2, filp->f_pos,
PARENT(ip), DT_DIR))
if (!dir_emit(ctx, "..", 2, PARENT(ip), DT_DIR))
return 0;
} else {
jfs_err("jfs_readdir called with "
"invalid offset!");
}
dtoffset->pn = 1;
dtoffset->index = 0;
filp->f_pos = dtpos;
ctx->pos = dtpos;
}

if (dtEmpty(ip)) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}

if ((rc = dtReadNext(ip, &filp->f_pos, &btstack))) {
if ((rc = dtReadNext(ip, &ctx->pos, &btstack))) {
jfs_err("jfs_readdir: unexpected rc = %d "
"from dtReadNext", rc);
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
/* get start leaf page and index */
DT_GETSEARCH(ip, btstack.top, bn, mp, p, index);

/* offset beyond directory eof ? */
if (bn < 0) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
return 0;
}
}
Expand All @@ -3180,7 +3175,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (dirent_buf == 0) {
DT_PUTPAGE(mp);
jfs_warn("jfs_readdir: __get_free_page failed!");
filp->f_pos = DIREND;
ctx->pos = DIREND;
return -ENOMEM;
}

Expand Down Expand Up @@ -3295,9 +3290,9 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)

jfs_dirent = (struct jfs_dirent *) dirent_buf;
while (jfs_dirents--) {
filp->f_pos = jfs_dirent->position;
if (filldir(dirent, jfs_dirent->name,
jfs_dirent->name_len, filp->f_pos,
ctx->pos = jfs_dirent->position;
if (!dir_emit(ctx, jfs_dirent->name,
jfs_dirent->name_len,
jfs_dirent->ino, DT_UNKNOWN))
goto out;
jfs_dirent = next_jfs_dirent(jfs_dirent);
Expand All @@ -3309,7 +3304,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
}

if (!overflow && (bn == 0)) {
filp->f_pos = DIREND;
ctx->pos = DIREND;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion fs/jfs/jfs_dtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,5 @@ extern int dtDelete(tid_t tid, struct inode *ip, struct component_name * key,
extern int dtModify(tid_t tid, struct inode *ip, struct component_name * key,
ino_t * orig_ino, ino_t new_ino, int flag);

extern int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir);
extern int jfs_readdir(struct file *file, struct dir_context *ctx);
#endif /* !_H_JFS_DTREE */
2 changes: 1 addition & 1 deletion fs/jfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ const struct inode_operations jfs_dir_inode_operations = {

const struct file_operations jfs_dir_operations = {
.read = generic_read_dir,
.readdir = jfs_readdir,
.iterate = jfs_readdir,
.fsync = jfs_fsync,
.unlocked_ioctl = jfs_ioctl,
#ifdef CONFIG_COMPAT
Expand Down

0 comments on commit 070a0eb

Please sign in to comment.