Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Feb 2017 18:32:35 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r313450 - in stable/11: lib/libc/gen lib/libc/sys sys/compat/freebsd32 sys/kern sys/sys
Message-ID:  <201702081832.v18IWZlC001828@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed Feb  8 18:32:35 2017
New Revision: 313450
URL: https://svnweb.freebsd.org/changeset/base/313450

Log:
  MFC 310638:
  Rename the 'flags' argument to getfsstat() to 'mode' and validate it.
  
  This argument is not a bitmask of flags, but only accepts a single value.
  Fail with EINVAL if an invalid value is passed to 'flag'.  Rename the
  'flags' argument to getmntinfo(3) to 'mode' as well to match.
  
  This is a followup to r308088.

Modified:
  stable/11/lib/libc/gen/getmntinfo.3
  stable/11/lib/libc/gen/getmntinfo.c
  stable/11/lib/libc/sys/getfsstat.2
  stable/11/sys/compat/freebsd32/freebsd32_misc.c
  stable/11/sys/compat/freebsd32/syscalls.master
  stable/11/sys/kern/syscalls.master
  stable/11/sys/kern/vfs_syscalls.c
  stable/11/sys/sys/syscallsubr.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libc/gen/getmntinfo.3
==============================================================================
--- stable/11/lib/libc/gen/getmntinfo.3	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/lib/libc/gen/getmntinfo.3	Wed Feb  8 18:32:35 2017	(r313450)
@@ -28,7 +28,7 @@
 .\"     @(#)getmntinfo.3	8.1 (Berkeley) 6/9/93
 .\" $FreeBSD$
 .\"
-.Dd June 9, 1993
+.Dd December 27, 2016
 .Dt GETMNTINFO 3
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .In sys/ucred.h
 .In sys/mount.h
 .Ft int
-.Fn getmntinfo "struct statfs **mntbufp" "int flags"
+.Fn getmntinfo "struct statfs **mntbufp" "int mode"
 .Sh DESCRIPTION
 The
 .Fn getmntinfo
@@ -55,7 +55,7 @@ The
 .Fn getmntinfo
 function
 passes its
-.Fa flags
+.Fa mode
 argument transparently to
 .Xr getfsstat 2 .
 .Sh RETURN VALUES

Modified: stable/11/lib/libc/gen/getmntinfo.c
==============================================================================
--- stable/11/lib/libc/gen/getmntinfo.c	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/lib/libc/gen/getmntinfo.c	Wed Feb  8 18:32:35 2017	(r313450)
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
  * Return information about mounted filesystems.
  */
 int
-getmntinfo(struct statfs **mntbufp, int flags)
+getmntinfo(struct statfs **mntbufp, int mode)
 {
 	static struct statfs *mntbuf;
 	static int mntsize;
@@ -50,7 +50,7 @@ getmntinfo(struct statfs **mntbufp, int 
 
 	if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0)
 		return (0);
-	if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
+	if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, mode)) < 0)
 		return (0);
 	while (bufsize <= mntsize * sizeof(struct statfs)) {
 		if (mntbuf)
@@ -58,7 +58,7 @@ getmntinfo(struct statfs **mntbufp, int 
 		bufsize = (mntsize + 1) * sizeof(struct statfs);
 		if ((mntbuf = malloc(bufsize)) == NULL)
 			return (0);
-		if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
+		if ((mntsize = getfsstat(mntbuf, bufsize, mode)) < 0)
 			return (0);
 	}
 	*mntbufp = mntbuf;

Modified: stable/11/lib/libc/sys/getfsstat.2
==============================================================================
--- stable/11/lib/libc/sys/getfsstat.2	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/lib/libc/sys/getfsstat.2	Wed Feb  8 18:32:35 2017	(r313450)
@@ -28,7 +28,7 @@
 .\"	@(#)getfsstat.2	8.3 (Berkeley) 5/25/95
 .\" $FreeBSD$
 .\"
-.Dd November 6, 2016
+.Dd December 27, 2016
 .Dt GETFSSTAT 2
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .In sys/ucred.h
 .In sys/mount.h
 .Ft int
-.Fn getfsstat "struct statfs *buf" "long bufsize" "int flags"
+.Fn getfsstat "struct statfs *buf" "long bufsize" "int mode"
 .Sh DESCRIPTION
 The
 .Fn getfsstat
@@ -74,11 +74,11 @@ is given as NULL,
 returns just the number of mounted file systems.
 .Pp
 Normally
-.Fa flags
+.Fa mode
 should be specified as
 .Dv MNT_WAIT .
 If
-.Fa flags
+.Fa mode
 is set to
 .Dv MNT_NOWAIT ,
 .Fn getfsstat
@@ -108,6 +108,12 @@ The
 .Fa buf
 argument
 points to an invalid address.
+.It Bq Er EINVAL
+.Fa mode
+is set to a value other than
+.Dv MNT_WAIT
+or
+.Dv MNT_NOWAIT .
 .It Bq Er EIO
 An
 .Tn I/O

Modified: stable/11/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32_misc.c	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/sys/compat/freebsd32/freebsd32_misc.c	Wed Feb  8 18:32:35 2017	(r313450)
@@ -254,7 +254,7 @@ freebsd4_freebsd32_getfsstat(struct thre
 
 	count = uap->bufsize / sizeof(struct statfs32);
 	size = count * sizeof(struct statfs);
-	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->flags);
+	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
 	if (size > 0) {
 		sp = buf;
 		copycount = count;

Modified: stable/11/sys/compat/freebsd32/syscalls.master
==============================================================================
--- stable/11/sys/compat/freebsd32/syscalls.master	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/sys/compat/freebsd32/syscalls.master	Wed Feb  8 18:32:35 2017	(r313450)
@@ -89,7 +89,7 @@
 				    obreak_args int
 18	AUE_GETFSSTAT	COMPAT4	{ int freebsd32_getfsstat( \
 				    struct statfs32 *buf, long bufsize, \
-				    int flags); }
+				    int mode); }
 19	AUE_LSEEK	COMPAT	{ int freebsd32_lseek(int fd, int offset, \
 				    int whence); }
 20	AUE_GETPID	NOPROTO	{ pid_t getpid(void); }
@@ -712,7 +712,7 @@
 				    off_t *sbytes, int flags); }
 394	AUE_NULL	UNIMPL	mac_syscall
 395	AUE_GETFSSTAT	NOPROTO	{ int getfsstat(struct statfs *buf, \
-				    long bufsize, int flags); }
+				    long bufsize, int mode); }
 396	AUE_STATFS	NOPROTO	{ int statfs(char *path, \
 				    struct statfs *buf); }
 397	AUE_FSTATFS	NOPROTO	{ int fstatfs(int fd, struct statfs *buf); }

Modified: stable/11/sys/kern/syscalls.master
==============================================================================
--- stable/11/sys/kern/syscalls.master	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/sys/kern/syscalls.master	Wed Feb  8 18:32:35 2017	(r313450)
@@ -85,7 +85,7 @@
 17	AUE_NULL	STD	{ int obreak(char *nsize); } break \
 				    obreak_args int
 18	AUE_GETFSSTAT	COMPAT4	{ int getfsstat(struct ostatfs *buf, \
-				    long bufsize, int flags); }
+				    long bufsize, int mode); }
 19	AUE_LSEEK	COMPAT	{ long lseek(int fd, long offset, \
 				    int whence); }
 20	AUE_GETPID	STD	{ pid_t getpid(void); }
@@ -707,7 +707,7 @@
 394	AUE_NULL	STD	{ int mac_syscall(const char *policy, \
 				    int call, void *arg); }
 395	AUE_GETFSSTAT	STD	{ int getfsstat(struct statfs *buf, \
-				    long bufsize, int flags); }
+				    long bufsize, int mode); }
 396	AUE_STATFS	STD	{ int statfs(char *path, \
 				    struct statfs *buf); }
 397	AUE_FSTATFS	STD	{ int fstatfs(int fd, struct statfs *buf); }

Modified: stable/11/sys/kern/vfs_syscalls.c
==============================================================================
--- stable/11/sys/kern/vfs_syscalls.c	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/sys/kern/vfs_syscalls.c	Wed Feb  8 18:32:35 2017	(r313450)
@@ -390,7 +390,7 @@ kern_fstatfs(struct thread *td, int fd, 
 struct getfsstat_args {
 	struct statfs *buf;
 	long bufsize;
-	int flags;
+	int mode;
 };
 #endif
 int
@@ -399,7 +399,7 @@ sys_getfsstat(td, uap)
 	register struct getfsstat_args /* {
 		struct statfs *buf;
 		long bufsize;
-		int flags;
+		int mode;
 	} */ *uap;
 {
 	size_t count;
@@ -408,7 +408,7 @@ sys_getfsstat(td, uap)
 	if (uap->bufsize < 0 || uap->bufsize > SIZE_MAX)
 		return (EINVAL);
 	error = kern_getfsstat(td, &uap->buf, uap->bufsize, &count,
-	    UIO_USERSPACE, uap->flags);
+	    UIO_USERSPACE, uap->mode);
 	if (error == 0)
 		td->td_retval[0] = count;
 	return (error);
@@ -421,13 +421,20 @@ sys_getfsstat(td, uap)
  */
 int
 kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
-    size_t *countp, enum uio_seg bufseg, int flags)
+    size_t *countp, enum uio_seg bufseg, int mode)
 {
 	struct mount *mp, *nmp;
 	struct statfs *sfsp, *sp, *sptmp, *tofree;
 	size_t count, maxcount;
 	int error;
 
+	switch (mode) {
+	case MNT_WAIT:
+	case MNT_NOWAIT:
+		break;
+	default:
+		return (EINVAL);
+	}
 restart:
 	maxcount = bufsize / sizeof(struct statfs);
 	if (bufsize == 0) {
@@ -461,7 +468,7 @@ restart:
 			continue;
 		}
 #endif
-		if (flags == MNT_WAIT) {
+		if (mode == MNT_WAIT) {
 			if (vfs_busy(mp, MBF_MNTLSTLOCK) != 0) {
 				/*
 				 * If vfs_busy() failed, and MBF_NOWAIT
@@ -490,10 +497,10 @@ restart:
 			sp->f_namemax = NAME_MAX;
 			sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
 			/*
-			 * If MNT_NOWAIT or MNT_LAZY is specified, do not
-			 * refresh the fsstat cache.
+			 * If MNT_NOWAIT is specified, do not refresh
+			 * the fsstat cache.
 			 */
-			if (flags != MNT_LAZY && flags != MNT_NOWAIT) {
+			if (mode != MNT_NOWAIT) {
 				error = VFS_STATFS(mp, sp);
 				if (error != 0) {
 					mtx_lock(&mountlist_mtx);
@@ -609,7 +616,7 @@ freebsd4_fstatfs(td, uap)
 struct freebsd4_getfsstat_args {
 	struct ostatfs *buf;
 	long bufsize;
-	int flags;
+	int mode;
 };
 #endif
 int
@@ -618,7 +625,7 @@ freebsd4_getfsstat(td, uap)
 	register struct freebsd4_getfsstat_args /* {
 		struct ostatfs *buf;
 		long bufsize;
-		int flags;
+		int mode;
 	} */ *uap;
 {
 	struct statfs *buf, *sp;
@@ -633,7 +640,7 @@ freebsd4_getfsstat(td, uap)
 		return (EINVAL);
 	size = count * sizeof(struct statfs);
 	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE,
-	    uap->flags);
+	    uap->mode);
 	td->td_retval[0] = count;
 	if (size != 0) {
 		sp = buf;

Modified: stable/11/sys/sys/syscallsubr.h
==============================================================================
--- stable/11/sys/sys/syscallsubr.h	Wed Feb  8 17:45:23 2017	(r313449)
+++ stable/11/sys/sys/syscallsubr.h	Wed Feb  8 18:32:35 2017	(r313450)
@@ -109,7 +109,7 @@ int	kern_futimens(struct thread *td, int
 int	kern_getdirentries(struct thread *td, int fd, char *buf, u_int count,
 	    long *basep, ssize_t *residp, enum uio_seg bufseg);
 int	kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
-	    size_t *countp, enum uio_seg bufseg, int flags);
+	    size_t *countp, enum uio_seg bufseg, int mode);
 int	kern_getitimer(struct thread *, u_int, struct itimerval *);
 int	kern_getppid(struct thread *);
 int	kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702081832.v18IWZlC001828>