Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb6f619b authored by Al Viro's avatar Al Viro
Browse files

[readdir] introduce ->iterate(), ctx->pos, dir_emit()



New method - ->iterate(file, ctx).  That's the replacement for ->readdir();
it takes callback from ctx->actor, uses ctx->pos instead of file->f_pos and
calls dir_emit(ctx, ...) instead of filldir(data, ...).  It does *not*
update file->f_pos (or look at it, for that matter); iterate_dir() does the
update.

Note that dir_emit() takes the offset from ctx->pos (and eventually
filldir_t will lose that argument).

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 5c0ba4e0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned i
		error = buf.error;
	lastdirent = buf.previous;
	if (lastdirent) {
		if (put_user(arg.file->f_pos, &lastdirent->d_off))
		if (put_user(buf.ctx.pos, &lastdirent->d_off))
			error = -EFAULT;
		else
			error = count - buf.count;
+15 −4
Original line number Diff line number Diff line
@@ -391,8 +391,7 @@ static int coda_readdir(struct file *coda_file, void *buf, filldir_t filldir)
	if (!host_file->f_op)
		return -ENOTDIR;

	if (host_file->f_op->readdir)
	{
	if (host_file->f_op->readdir) {
		/* potemkin case: we were handed a directory inode.
		 * We can't use vfs_readdir because we have to keep the file
		 * position in sync between the coda_file and the host_file.
@@ -410,8 +409,20 @@ static int coda_readdir(struct file *coda_file, void *buf, filldir_t filldir)

		coda_file->f_pos = host_file->f_pos;
		mutex_unlock(&host_inode->i_mutex);
	} else if (host_file->f_op->iterate) {
		struct inode *host_inode = file_inode(host_file);
		struct dir_context *ctx = buf;

		mutex_lock(&host_inode->i_mutex);
		ret = -ENOENT;
		if (!IS_DEADDIR(host_inode)) {
			ret = host_file->f_op->iterate(host_file, ctx);
			file_accessed(host_file);
		}
	else /* Venus: we must read Venus dirents from a file */
		mutex_unlock(&host_inode->i_mutex);

		coda_file->f_pos = ctx->pos;
	} else /* Venus: we must read Venus dirents from a file */
		ret = coda_venus_readdir(coda_file, buf, filldir);

	return ret;
+2 −2
Original line number Diff line number Diff line
@@ -975,7 +975,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
		error = buf.error;
	lastdirent = buf.previous;
	if (lastdirent) {
		if (put_user(f.file->f_pos, &lastdirent->d_off))
		if (put_user(buf.ctx.pos, &lastdirent->d_off))
			error = -EFAULT;
		else
			error = count - buf.count;
@@ -1062,7 +1062,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
		error = buf.error;
	lastdirent = buf.previous;
	if (lastdirent) {
		typeof(lastdirent->d_off) d_off = f.file->f_pos;
		typeof(lastdirent->d_off) d_off = buf.ctx.pos;
		if (__put_user_unaligned(d_off, &lastdirent->d_off))
			error = -EFAULT;
		else
+1 −1
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ static int get_name(const struct path *path, char *name, struct dentry *child)
		goto out;

	error = -EINVAL;
	if (!file->f_op->readdir)
	if (!file->f_op->readdir && !file->f_op->iterate)
		goto out_close;

	buffer.name = name;
+8 −6
Original line number Diff line number Diff line
@@ -240,11 +240,16 @@ struct name_list {
	struct list_head list;
};

struct nfs4_dir_ctx {
	struct dir_context ctx;
	struct list_head names;
};

static int
nfsd4_build_namelist(void *arg, const char *name, int namlen,
		loff_t offset, u64 ino, unsigned int d_type)
{
	struct list_head *names = arg;
	struct nfs4_dir_ctx *ctx = arg;
	struct name_list *entry;

	if (namlen != HEXDIR_LEN - 1)
@@ -254,7 +259,7 @@ nfsd4_build_namelist(void *arg, const char *name, int namlen,
		return -ENOMEM;
	memcpy(entry->name, name, HEXDIR_LEN - 1);
	entry->name[HEXDIR_LEN - 1] = '\0';
	list_add(&entry->list, names);
	list_add(&entry->list, &ctx->names);
	return 0;
}

@@ -263,10 +268,7 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
{
	const struct cred *original_cred;
	struct dentry *dir = nn->rec_file->f_path.dentry;
	struct {
		struct dir_context ctx;
		struct list_head names;
	} ctx;
	struct nfs4_dir_ctx ctx;
	int status;

	status = nfs4_save_creds(&original_cred);
Loading