Skip to content

Commit

Permalink
Change VOP_READDIR's cookies argument to a **uint64_t
Browse files Browse the repository at this point in the history
The cookies argument is only used by the NFS server.  NFSv2 defines the
cookie as 32 bits on the wire, but NFSv3 increased it to 64 bits.  Our
VOP_READDIR, however, has always defined it as u_long, which is 32 bits
on some architectures.  Change it to 64 bits on all architectures.  This
doesn't matter for any in-tree file systems, but it matters for some
FUSE file systems that use 64-bit directory cookies.

PR:             260375
Reviewed by:    rmacklem
Differential Revision: https://reviews.freebsd.org/D33404
  • Loading branch information
asomers committed Dec 16, 2021
1 parent 32fbc5d commit b214fcc
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 43 deletions.
6 changes: 3 additions & 3 deletions share/man/man9/VOP_READDIR.9
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd March 30, 2020
.Dd December 13, 2021
.Dt VOP_READDIR 9
.Os
.Sh NAME
Expand All @@ -39,7 +39,7 @@
.In sys/dirent.h
.In sys/vnode.h
.Ft int
.Fn VOP_READDIR "struct vnode *vp" "struct uio *uio" "struct ucred *cred" "int *eofflag" "int *ncookies" "u_long **cookies"
.Fn VOP_READDIR "struct vnode *vp" "struct uio *uio" "struct ucred *cred" "int *eofflag" "int *ncookies" "uint64_t **cookies"
.Sh DESCRIPTION
Read directory entries.
.Bl -tag -width ncookies
Expand Down Expand Up @@ -92,7 +92,7 @@ Memory for the cookies should be allocated using:
.Bd -literal
...;
*ncookies = number of entries read;
*cookies = malloc(*ncookies * sizeof(u_long), M_TEMP, M_WAITOK);
*cookies = malloc(*ncookies * sizeof(**cookies), M_TEMP, M_WAITOK);
.Ed
.Sh ERRORS
.Bl -tag -width Er
Expand Down
8 changes: 4 additions & 4 deletions sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ zfs_rmdir(znode_t *dzp, const char *name, znode_t *cwd, cred_t *cr, int flags)
/* ARGSUSED */
static int
zfs_readdir(vnode_t *vp, zfs_uio_t *uio, cred_t *cr, int *eofp,
int *ncookies, ulong_t **cookies)
int *ncookies, uint64_t **cookies)
{
znode_t *zp = VTOZ(vp);
iovec_t *iovp;
Expand All @@ -1687,7 +1687,7 @@ zfs_readdir(vnode_t *vp, zfs_uio_t *uio, cred_t *cr, int *eofp,
boolean_t check_sysattrs;
uint8_t type;
int ncooks;
ulong_t *cooks = NULL;
uint64_t *cooks = NULL;
int flags = 0;

ZFS_ENTER(zfsvfs);
Expand Down Expand Up @@ -1764,7 +1764,7 @@ zfs_readdir(vnode_t *vp, zfs_uio_t *uio, cred_t *cr, int *eofp,
*/
ncooks = zfs_uio_resid(uio) / (sizeof (struct dirent) -
sizeof (((struct dirent *)NULL)->d_name) + 1);
cooks = malloc(ncooks * sizeof (ulong_t), M_TEMP, M_WAITOK);
cooks = malloc(ncooks * sizeof (*cooks), M_TEMP, M_WAITOK);
*cookies = cooks;
*ncookies = ncooks;
}
Expand Down Expand Up @@ -4720,7 +4720,7 @@ struct vop_readdir_args {
struct ucred *a_cred;
int *a_eofflag;
int *a_ncookies;
ulong_t **a_cookies;
uint64_t **a_cookies;
};
#endif

Expand Down
9 changes: 4 additions & 5 deletions sys/fs/cd9660/cd9660_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ struct isoreaddir {
struct uio *uio;
off_t uio_off;
int eofflag;
u_long *cookies;
uint64_t *cookies;
int ncookies;
};

Expand Down Expand Up @@ -464,7 +464,7 @@ cd9660_readdir(ap)
struct ucred *a_cred;
int *a_eofflag;
int *a_ncookies;
u_long **a_cookies;
uint64_t **a_cookies;
} */ *ap;
{
struct uio *uio = ap->a_uio;
Expand All @@ -481,7 +481,7 @@ cd9660_readdir(ap)
int reclen;
u_short namelen;
u_int ncookies = 0;
u_long *cookies = NULL;
uint64_t *cookies = NULL;
cd_ino_t ino;

dp = VTOI(vdp);
Expand All @@ -504,8 +504,7 @@ cd9660_readdir(ap)
* Guess the number of cookies needed.
*/
ncookies = uio->uio_resid / 16;
cookies = malloc(ncookies * sizeof(u_long),
M_TEMP, M_WAITOK);
cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
idp->cookies = cookies;
idp->ncookies = ncookies;
}
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/ext2fs/ext2_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ext2_readdir(struct vop_readdir_args *ap)
struct buf *bp;
struct inode *ip;
struct ext2fs_direct_2 *dp, *edp;
u_long *cookies;
uint64_t *cookies;
struct dirent dstdp;
off_t offset, startoffset;
size_t readcnt, skipcnt;
Expand Down
6 changes: 3 additions & 3 deletions sys/fs/fuse/fuse_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ fuse_internal_readdir(struct vnode *vp,
struct fuse_filehandle *fufh,
struct fuse_iov *cookediov,
int *ncookies,
u_long *cookies)
uint64_t *cookies)
{
int err = 0;
struct fuse_dispatcher fdi;
Expand Down Expand Up @@ -625,15 +625,15 @@ fuse_internal_readdir_processdata(struct uio *uio,
size_t bufsize,
struct fuse_iov *cookediov,
int *ncookies,
u_long **cookiesp)
uint64_t **cookiesp)
{
int err = 0;
int oreclen;
size_t freclen;

struct dirent *de;
struct fuse_dirent *fudge;
u_long *cookies;
uint64_t *cookies;

cookies = *cookiesp;
if (bufsize < FUSE_NAME_OFFSET)
Expand Down
4 changes: 2 additions & 2 deletions sys/fs/fuse/fuse_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ struct pseudo_dirent {
};
int fuse_internal_readdir(struct vnode *vp, struct uio *uio, off_t startoff,
struct fuse_filehandle *fufh, struct fuse_iov *cookediov, int *ncookies,
u_long *cookies);
uint64_t *cookies);
int fuse_internal_readdir_processdata(struct uio *uio, off_t startoff,
int *fnd_start, size_t reqsize, void *buf, size_t bufsize,
struct fuse_iov *cookediov, int *ncookies, u_long **cookiesp);
struct fuse_iov *cookediov, int *ncookies, uint64_t **cookiesp);

/* remove */

Expand Down
4 changes: 2 additions & 2 deletions sys/fs/fuse/fuse_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ fuse_vnop_read(struct vop_read_args *ap)
struct ucred *a_cred;
int *a_eofflag;
int *a_ncookies;
u_long **a_cookies;
uint64_t **a_cookies;
};
*/
static int
Expand All @@ -1742,7 +1742,7 @@ fuse_vnop_readdir(struct vop_readdir_args *ap)
struct fuse_filehandle *fufh = NULL;
struct fuse_iov cookediov;
int err = 0;
u_long *cookies;
uint64_t *cookies;
off_t startoff;
ssize_t tresid;
int ncookies;
Expand Down
4 changes: 2 additions & 2 deletions sys/fs/msdosfs/msdosfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ msdosfs_readdir(struct vop_readdir_args *ap)
struct direntry *dentp;
struct dirent dirbuf;
struct uio *uio = ap->a_uio;
u_long *cookies = NULL;
uint64_t *cookies = NULL;
int ncookies = 0;
off_t offset, off;
int chksum = -1;
Expand Down Expand Up @@ -1553,7 +1553,7 @@ msdosfs_readdir(struct vop_readdir_args *ap)

if (ap->a_ncookies) {
ncookies = uio->uio_resid / 16;
cookies = malloc(ncookies * sizeof(u_long), M_TEMP,
cookies = malloc(ncookies * sizeof(*cookies), M_TEMP,
M_WAITOK);
*ap->a_cookies = cookies;
*ap->a_ncookies = ncookies;
Expand Down
4 changes: 2 additions & 2 deletions sys/fs/nfsserver/nfs_nfsdport.c
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ nfsrvd_readdir(struct nfsrv_descript *nd, int isdgram,
int nlen, error = 0, getret = 1;
int siz, cnt, fullsiz, eofflag, ncookies;
u_int64_t off, toff, verf __unused;
u_long *cookies = NULL, *cookiep;
uint64_t *cookies = NULL, *cookiep;
struct uio io;
struct iovec iv;
int is_ufs;
Expand Down Expand Up @@ -2309,7 +2309,7 @@ nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram,
int siz, cnt, fullsiz, eofflag, ncookies, entrycnt;
caddr_t bpos0, bpos1;
u_int64_t off, toff, verf __unused;
u_long *cookies = NULL, *cookiep;
uint64_t *cookies = NULL, *cookiep;
nfsattrbit_t attrbits, rderrbits, savbits;
struct uio io;
struct iovec iv;
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/smbfs/smbfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ smbfs_readdir(ap)
struct uio *a_uio;
struct ucred *a_cred;
int *a_eofflag;
u_long *a_cookies;
uint64_t *a_cookies;
int a_ncookies;
} */ *ap;
{
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/tmpfs/tmpfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ struct tmpfs_dirent * tmpfs_dir_lookup(struct tmpfs_node *node,
struct tmpfs_node *f,
struct componentname *cnp);
int tmpfs_dir_getdents(struct tmpfs_mount *, struct tmpfs_node *,
struct uio *, int, u_long *, int *);
struct uio *, int, uint64_t *, int *);
int tmpfs_dir_whiteout_add(struct vnode *, struct componentname *);
void tmpfs_dir_whiteout_remove(struct vnode *, struct componentname *);
int tmpfs_reg_resize(struct vnode *, off_t, boolean_t);
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/tmpfs/tmpfs_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ tmpfs_dir_getdotdotdent(struct tmpfs_mount *tm, struct tmpfs_node *node,
*/
int
tmpfs_dir_getdents(struct tmpfs_mount *tm, struct tmpfs_node *node,
struct uio *uio, int maxcookies, u_long *cookies, int *ncookies)
struct uio *uio, int maxcookies, uint64_t *cookies, int *ncookies)
{
struct tmpfs_dir_cursor dc;
struct tmpfs_dirent *de, *nde;
Expand Down
2 changes: 1 addition & 1 deletion sys/fs/tmpfs/tmpfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ tmpfs_readdir(struct vop_readdir_args *va)
struct uio *uio;
struct tmpfs_mount *tm;
struct tmpfs_node *node;
u_long **cookies;
uint64_t **cookies;
int *eofflag, *ncookies;
ssize_t startresid;
int error, maxcookies;
Expand Down
7 changes: 3 additions & 4 deletions sys/fs/udf/udf_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ udf_cmpname(char *cs0string, char *cmpname, int cs0len, int cmplen, struct udf_m

struct udf_uiodir {
struct dirent *dirent;
u_long *cookies;
uint64_t *cookies;
int ncookies;
int acookies;
int eofflag;
Expand Down Expand Up @@ -787,7 +787,7 @@ udf_readdir(struct vop_readdir_args *a)
struct fileid_desc *fid;
struct udf_uiodir uiodir;
struct udf_dirstream *ds;
u_long *cookies = NULL;
uint64_t *cookies = NULL;
int ncookies;
int error = 0;

Expand All @@ -804,8 +804,7 @@ udf_readdir(struct vop_readdir_args *a)
* it left off.
*/
ncookies = uio->uio_resid / 8;
cookies = malloc(sizeof(u_long) * ncookies,
M_TEMP, M_WAITOK);
cookies = malloc(sizeof(*cookies) * ncookies, M_TEMP, M_WAITOK);
if (cookies == NULL)
return (ENOMEM);
uiodir.ncookies = ncookies;
Expand Down
10 changes: 5 additions & 5 deletions sys/fs/unionfs/union_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ unionfs_readdir(struct vop_readdir_args *ap)
struct thread *td;
struct vattr va;

u_long *cookies_bk;
uint64_t *cookies_bk;
int error;
int eofflag;
int locked;
Expand Down Expand Up @@ -1660,17 +1660,17 @@ unionfs_readdir(struct vop_readdir_args *ap)
if (cookies_bk != NULL) {
/* merge cookies */
int size;
u_long *newcookies, *pos;
uint64_t *newcookies, *pos;

size = *(ap->a_ncookies) + ncookies_bk;
newcookies = (u_long *) malloc(size * sizeof(u_long),
newcookies = (uint64_t *) malloc(size * sizeof(*newcookies),
M_TEMP, M_WAITOK);
pos = newcookies;

memcpy(pos, cookies_bk, ncookies_bk * sizeof(u_long));
memcpy(pos, cookies_bk, ncookies_bk * sizeof(*newcookies));
pos += ncookies_bk;
memcpy(pos, *(ap->a_cookies),
*(ap->a_ncookies) * sizeof(u_long));
*(ap->a_ncookies) * sizeof(*newcookies));
free(cookies_bk, M_TEMP);
free(*(ap->a_cookies), M_TEMP);
*(ap->a_ncookies) = size;
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/uipc_mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ struct vop_readdir_args {
struct ucred *a_cred;
int *a_eofflag;
int *a_ncookies;
u_long **a_cookies;
uint64_t **a_cookies;
};
#endif

Expand Down
2 changes: 1 addition & 1 deletion sys/kern/vfs_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6419,7 +6419,7 @@ vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
("NULL ap->a_cookies value with non-NULL ap->a_ncookies!"));

*ap->a_cookies = realloc(*ap->a_cookies,
(*ap->a_ncookies + 1) * sizeof(u_long), M_TEMP, M_WAITOK | M_ZERO);
(*ap->a_ncookies + 1) * sizeof(uint64_t), M_TEMP, M_WAITOK | M_ZERO);
(*ap->a_cookies)[*ap->a_ncookies] = off;
*ap->a_ncookies += 1;
return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/vnode_if.src
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ vop_readdir {
IN struct ucred *cred;
INOUT int *eofflag;
OUT int *ncookies;
INOUT u_long **cookies;
INOUT uint64_t **cookies;
};


Expand Down
2 changes: 1 addition & 1 deletion sys/sys/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1400044
#define __FreeBSD_version 1400045

/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
Expand Down
4 changes: 2 additions & 2 deletions sys/ufs/ufs/ufs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,15 +2336,15 @@ ufs_readdir(ap)
struct ucred *a_cred;
int *a_eofflag;
int *a_ncookies;
u_long **a_cookies;
uint64_t **a_cookies;
} */ *ap;
{
struct vnode *vp = ap->a_vp;
struct uio *uio = ap->a_uio;
struct buf *bp;
struct inode *ip;
struct direct *dp, *edp;
u_long *cookies;
uint64_t *cookies;
struct dirent dstdp;
off_t offset, startoffset;
size_t readcnt, skipcnt;
Expand Down

0 comments on commit b214fcc

Please sign in to comment.