Skip to content

Commit

Permalink
fs: support d_off in readdir for all filesystems
Browse files Browse the repository at this point in the history
This is a trivial patch to set dirent.d_off in all readdir
implementations. As mentioned in readdir(3): "The  value  returned in
d_off is the same as would be returned by calling telldir(3) at the
current position in the directory stream."

Signed-off-by: Fotis Xenakis <foxen@windowslive.com>
Message-Id: <VI1PR03MB377326C560EA102C1B02EB4BA67C9@VI1PR03MB3773.eurprd03.prod.outlook.com>
  • Loading branch information
foxeng authored and nyh committed Mar 31, 2021
1 parent 7cd3392 commit 2eda045
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ zfs_lookup(struct vnode *dvp, char *nm, struct vnode **vpp)

ASSERT0(!(nm[0] == '.' && nm[1] == '\0'));
ASSERT0(!(nm[0] == '.' && nm[1] == '.' && nm[2] == '\0'));

ZFS_ENTER(zfsvfs);
ZFS_VERIFY_ZP(dzp);

Expand Down Expand Up @@ -1974,6 +1974,7 @@ zfs_readdir(struct vnode *dvp, struct file *fp, struct dirent *dir)
} else {
file_setoffset(fp, file_offset(fp) + 1);
}
dir->d_off = file_offset(fp);

zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */

Expand Down Expand Up @@ -4714,7 +4715,7 @@ zfs_getpages(struct vnode *vp, vm_page_t *m, int count, int reqpage)
* FreeBSD's extended attributes namespace defines file name prefix for ZFS'
* extended attribute name:
*
* NAMESPACE PREFIX
* NAMESPACE PREFIX
* system freebsd:system:
* user (none, can be used to access ZFS fsattr(5) attributes
* created on Solaris)
Expand Down
2 changes: 2 additions & 0 deletions fs/devfs/devfs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ devfs_readdir(struct vnode *vp, struct file *fp, struct dirent *dir)

DPRINTF(("devfs_readdir: %s\n", dir->d_name));
fp->f_offset++;
dir->d_off = fp->f_offset;

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions fs/pseudofs/pseudofs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ int readdir(vnode *vp, file *fp, dirent *dir) {
dir->d_fileno = fp->f_offset;

fp->f_offset++;
dir->d_off = fp->f_offset;

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions fs/ramfs/ramfs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ ramfs_readdir(struct vnode *vp, struct file *fp, struct dirent *dir)
// dir->d_namelen = strlen(dir->d_name);

fp->f_offset++;
dir->d_off = fp->f_offset;

mutex_unlock(&ramfs_lock);
return 0;
Expand Down
1 change: 1 addition & 0 deletions fs/rofs/rofs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ static int rofs_readdir(struct vnode *vnode, struct file *fp, struct dirent *dir
}

fp->f_offset++;
dir->d_off = fp->f_offset;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/nfs/nfs_vnops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ static int nfs_op_readdir(struct vnode *vp, struct file *fp, struct dirent *dir)
// Fill dirent infos
assert(sizeof(ino_t) == sizeof(nfsdirent->inode));
dir->d_ino = nfsdirent->inode;
// FIXME: not filling dir->d_off
// FIXME: not filling dir->d_reclen
dir->d_type = IFTODT(nfsdirent->mode & S_IFMT);
strlcpy((char *) &dir->d_name, nfsdirent->name, sizeof(dir->d_name));

// iterate
fp->f_offset++;
dir->d_off = fp->f_offset;

return 0;
}
Expand Down

0 comments on commit 2eda045

Please sign in to comment.