git: b214fcceacad - main - Change VOP_READDIR's cookies argument to a **uint64_t

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Thu, 16 Dec 2021 03:55:03 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=b214fcceacad6b842545150664bd2695c1c2b34f

commit b214fcceacad6b842545150664bd2695c1c2b34f
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-12-14 02:37:27 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-12-16 03:54:57 +0000

    Change VOP_READDIR's cookies argument to a **uint64_t
    
    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
---
 share/man/man9/VOP_READDIR.9                             |  6 +++---
 sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c |  8 ++++----
 sys/fs/cd9660/cd9660_vnops.c                             |  9 ++++-----
 sys/fs/ext2fs/ext2_lookup.c                              |  2 +-
 sys/fs/fuse/fuse_internal.c                              |  6 +++---
 sys/fs/fuse/fuse_internal.h                              |  4 ++--
 sys/fs/fuse/fuse_vnops.c                                 |  4 ++--
 sys/fs/msdosfs/msdosfs_vnops.c                           |  4 ++--
 sys/fs/nfsserver/nfs_nfsdport.c                          |  4 ++--
 sys/fs/smbfs/smbfs_vnops.c                               |  2 +-
 sys/fs/tmpfs/tmpfs.h                                     |  2 +-
 sys/fs/tmpfs/tmpfs_subr.c                                |  2 +-
 sys/fs/tmpfs/tmpfs_vnops.c                               |  2 +-
 sys/fs/udf/udf_vnops.c                                   |  7 +++----
 sys/fs/unionfs/union_vnops.c                             | 10 +++++-----
 sys/kern/uipc_mqueue.c                                   |  2 +-
 sys/kern/vfs_subr.c                                      |  2 +-
 sys/kern/vnode_if.src                                    |  2 +-
 sys/sys/param.h                                          |  2 +-
 sys/ufs/ufs/ufs_vnops.c                                  |  4 ++--
 20 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/share/man/man9/VOP_READDIR.9 b/share/man/man9/VOP_READDIR.9
index 3f4d9b566636..70e3aa1a46bc 100644
--- a/share/man/man9/VOP_READDIR.9
+++ b/share/man/man9/VOP_READDIR.9
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd March 30, 2020
+.Dd December 13, 2021
 .Dt VOP_READDIR 9
 .Os
 .Sh NAME
@@ -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
@@ -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
diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
index 2f7019b92498..1dde0ac43f1a 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c
@@ -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;
@@ -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);
@@ -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;
 	}
@@ -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
 
diff --git a/sys/fs/cd9660/cd9660_vnops.c b/sys/fs/cd9660/cd9660_vnops.c
index 0ddf73548e3f..f75b0a29900a 100644
--- a/sys/fs/cd9660/cd9660_vnops.c
+++ b/sys/fs/cd9660/cd9660_vnops.c
@@ -367,7 +367,7 @@ struct isoreaddir {
 	struct uio *uio;
 	off_t uio_off;
 	int eofflag;
-	u_long *cookies;
+	uint64_t *cookies;
 	int ncookies;
 };
 
@@ -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;
@@ -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);
@@ -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;
 	}
diff --git a/sys/fs/ext2fs/ext2_lookup.c b/sys/fs/ext2fs/ext2_lookup.c
index 3b435bf96a8a..3294ad3401ff 100644
--- a/sys/fs/ext2fs/ext2_lookup.c
+++ b/sys/fs/ext2fs/ext2_lookup.c
@@ -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;
diff --git a/sys/fs/fuse/fuse_internal.c b/sys/fs/fuse/fuse_internal.c
index 4a09bc9394cf..aea9fc966225 100644
--- a/sys/fs/fuse/fuse_internal.c
+++ b/sys/fs/fuse/fuse_internal.c
@@ -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;
@@ -625,7 +625,7 @@ 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;
@@ -633,7 +633,7 @@ fuse_internal_readdir_processdata(struct uio *uio,
 
 	struct dirent *de;
 	struct fuse_dirent *fudge;
-	u_long *cookies;
+	uint64_t *cookies;
 
 	cookies = *cookiesp;
 	if (bufsize < FUSE_NAME_OFFSET)
diff --git a/sys/fs/fuse/fuse_internal.h b/sys/fs/fuse/fuse_internal.h
index e9fa3857227a..c17eff2acac3 100644
--- a/sys/fs/fuse/fuse_internal.h
+++ b/sys/fs/fuse/fuse_internal.h
@@ -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 */
 
diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c
index 67c08f6ee47c..4a9396a769dd 100644
--- a/sys/fs/fuse/fuse_vnops.c
+++ b/sys/fs/fuse/fuse_vnops.c
@@ -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
@@ -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;
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index a431190d7089..c071d9f44d86 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -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;
@@ -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;
diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index cce291a8f1f6..5c3280b55d7a 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -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;
@@ -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;
diff --git a/sys/fs/smbfs/smbfs_vnops.c b/sys/fs/smbfs/smbfs_vnops.c
index ac32f13977db..7ae5fb303590 100644
--- a/sys/fs/smbfs/smbfs_vnops.c
+++ b/sys/fs/smbfs/smbfs_vnops.c
@@ -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;
 {
diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h
index bfa12b0382bc..cdff1daadf33 100644
--- a/sys/fs/tmpfs/tmpfs.h
+++ b/sys/fs/tmpfs/tmpfs.h
@@ -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);
diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index 41d9b6d5dcca..ca530fd72fdb 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -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;
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index a59a522d85ab..bdad78f66ea5 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -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;
diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c
index 2cda9ed75393..fd2d5c5c0439 100644
--- a/sys/fs/udf/udf_vnops.c
+++ b/sys/fs/udf/udf_vnops.c
@@ -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;
@@ -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;
 
@@ -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;
diff --git a/sys/fs/unionfs/union_vnops.c b/sys/fs/unionfs/union_vnops.c
index ef0c4300ff0b..6cedfa3d142d 100644
--- a/sys/fs/unionfs/union_vnops.c
+++ b/sys/fs/unionfs/union_vnops.c
@@ -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;
@@ -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;
diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c
index 24ed1be6bf65..f2e0240436f4 100644
--- a/sys/kern/uipc_mqueue.c
+++ b/sys/kern/uipc_mqueue.c
@@ -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
 
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 7b358b4d8260..3218a3f7b6a0 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -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);
diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src
index 8ec2d3ef90fd..2f090ce044bd 100644
--- a/sys/kern/vnode_if.src
+++ b/sys/kern/vnode_if.src
@@ -392,7 +392,7 @@ vop_readdir {
 	IN struct ucred *cred;
 	INOUT int *eofflag;
 	OUT int *ncookies;
-	INOUT u_long **cookies;
+	INOUT uint64_t **cookies;
 };
 
 
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 1c9e9b8df407..03c66c2d1b79 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -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,
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index 02dada0c63a2..89454d0effff 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -2336,7 +2336,7 @@ 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;
@@ -2344,7 +2344,7 @@ ufs_readdir(ap)
 	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;