Module Name:    src
Committed By:   riastradh
Date:           Sat Apr 22 13:52:55 UTC 2023

Modified Files:
        src/sys/kern: kern_event.c sys_descrip.c sys_pipe.c sys_socket.c
            vfs_vnops.c
        src/sys/sys: file.h

Log Message:
file(9): New fo_fpathconf operation.

XXX kernel revbump -- struct fileops API and ABI change


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/kern/kern_event.c
cvs rdiff -u -r1.41 -r1.42 src/sys/kern/sys_descrip.c
cvs rdiff -u -r1.158 -r1.159 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/sys_socket.c
cvs rdiff -u -r1.239 -r1.240 src/sys/kern/vfs_vnops.c
cvs rdiff -u -r1.90 -r1.91 src/sys/sys/file.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_event.c
diff -u src/sys/kern/kern_event.c:1.147 src/sys/kern/kern_event.c:1.148
--- src/sys/kern/kern_event.c:1.147	Sun Apr  9 09:18:09 2023
+++ src/sys/kern/kern_event.c	Sat Apr 22 13:52:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_event.c,v 1.147 2023/04/09 09:18:09 riastradh Exp $	*/
+/*	$NetBSD: kern_event.c,v 1.148 2023/04/22 13:52:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #endif /* _KERNEL_OPT */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.147 2023/04/09 09:18:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.148 2023/04/22 13:52:54 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -95,6 +95,7 @@ static int	kqueue_kqfilter(file_t *, str
 static int	kqueue_stat(file_t *, struct stat *);
 static int	kqueue_close(file_t *);
 static void	kqueue_restart(file_t *);
+static int	kqueue_fpathconf(file_t *, int, register_t *);
 static int	kqueue_register(struct kqueue *, struct kevent *);
 static void	kqueue_doclose(struct kqueue *, struct klist *, int);
 
@@ -186,6 +187,7 @@ static const struct fileops kqueueops = 
 	.fo_close = kqueue_close,
 	.fo_kqfilter = kqueue_kqfilter,
 	.fo_restart = kqueue_restart,
+	.fo_fpathconf = kqueue_fpathconf,
 };
 
 static void
@@ -2249,6 +2251,13 @@ kqueue_restart(file_t *fp)
 	mutex_spin_exit(&kq->kq_lock);
 }
 
+static int
+kqueue_fpathconf(struct file *fp, int name, register_t *retval)
+{
+
+	return EINVAL;
+}
+
 /*
  * Scan through the list of events on fp (for a maximum of maxevents),
  * returning the results in to ulistp. Timeout is determined by tsp; if

Index: src/sys/kern/sys_descrip.c
diff -u src/sys/kern/sys_descrip.c:1.41 src/sys/kern/sys_descrip.c:1.42
--- src/sys/kern/sys_descrip.c:1.41	Sat Apr 22 13:52:46 2023
+++ src/sys/kern/sys_descrip.c	Sat Apr 22 13:52:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_descrip.c,v 1.41 2023/04/22 13:52:46 riastradh Exp $	*/
+/*	$NetBSD: sys_descrip.c,v 1.42 2023/04/22 13:52:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.41 2023/04/22 13:52:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.42 2023/04/22 13:52:54 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -571,41 +571,21 @@ sys_fpathconf(struct lwp *l, const struc
 		syscallarg(int)	fd;
 		syscallarg(int)	name;
 	} */
-	int fd, error;
+	int fd, name, error;
 	file_t *fp;
 
 	fd = SCARG(uap, fd);
+	name = SCARG(uap, name);
 	error = 0;
 
-	if ((fp = fd_getfile(fd)) == NULL) {
-		return (EBADF);
-	}
-	switch (fp->f_type) {
-	case DTYPE_SOCKET:
-	case DTYPE_PIPE:
-		if (SCARG(uap, name) != _PC_PIPE_BUF)
-			error = EINVAL;
-		else
-			*retval = PIPE_BUF;
-		break;
-
-	case DTYPE_VNODE:
-		vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY);
-		error = VOP_PATHCONF(fp->f_vnode, SCARG(uap, name), retval);
-		VOP_UNLOCK(fp->f_vnode);
-		break;
-
-	case DTYPE_KQUEUE:
-		error = EINVAL;
-		break;
-
-	default:
+	if ((fp = fd_getfile(fd)) == NULL)
+		return EBADF;
+	if (fp->f_ops->fo_fpathconf == NULL)
 		error = EOPNOTSUPP;
-		break;
-	}
-
+	else
+		error = (*fp->f_ops->fo_fpathconf)(fp, name, retval);
 	fd_putfile(fd);
-	return (error);
+	return error;
 }
 
 /*

Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.158 src/sys/kern/sys_pipe.c:1.159
--- src/sys/kern/sys_pipe.c:1.158	Mon Oct 11 01:07:36 2021
+++ src/sys/kern/sys_pipe.c	Sat Apr 22 13:52:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pipe.c,v 1.158 2021/10/11 01:07:36 thorpej Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.159 2023/04/22 13:52:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.158 2021/10/11 01:07:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.159 2023/04/22 13:52:54 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -100,6 +100,7 @@ static int	pipe_kqfilter(file_t *, struc
 static int	pipe_stat(file_t *, struct stat *);
 static int	pipe_ioctl(file_t *, u_long, void *);
 static void	pipe_restart(file_t *);
+static int	pipe_fpathconf(file_t *, int, register_t *);
 
 static const struct fileops pipeops = {
 	.fo_name = "pipe",
@@ -112,6 +113,7 @@ static const struct fileops pipeops = {
 	.fo_close = pipe_close,
 	.fo_kqfilter = pipe_kqfilter,
 	.fo_restart = pipe_restart,
+	.fo_fpathconf = pipe_fpathconf,
 };
 
 /*
@@ -913,6 +915,19 @@ pipe_restart(file_t *fp)
 	mutex_exit(pipe->pipe_lock);
 }
 
+static int
+pipe_fpathconf(struct file *fp, int name, register_t *retval)
+{
+
+	switch (name) {
+	case _PC_PIPE_BUF:
+		*retval = PIPE_BUF;
+		return 0;
+	default:
+		return EINVAL;
+	}
+}
+
 static void
 pipe_free_kmem(struct pipe *pipe)
 {

Index: src/sys/kern/sys_socket.c
diff -u src/sys/kern/sys_socket.c:1.79 src/sys/kern/sys_socket.c:1.80
--- src/sys/kern/sys_socket.c:1.79	Tue Nov 17 03:22:33 2020
+++ src/sys/kern/sys_socket.c	Sat Apr 22 13:52:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_socket.c,v 1.79 2020/11/17 03:22:33 chs Exp $	*/
+/*	$NetBSD: sys_socket.c,v 1.80 2023/04/22 13:52:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.79 2020/11/17 03:22:33 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.80 2023/04/22 13:52:54 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,6 +80,8 @@ __KERNEL_RCSID(0, "$NetBSD: sys_socket.c
 #include <net/if.h>
 #include <net/route.h>
 
+static int soo_fpathconf(struct file *, int, register_t *);
+
 const struct fileops socketops = {
 	.fo_name = "socket",
 	.fo_read = soo_read,
@@ -91,6 +93,7 @@ const struct fileops socketops = {
 	.fo_close = soo_close,
 	.fo_kqfilter = soo_kqfilter,
 	.fo_restart = soo_restart,
+	.fo_fpathconf = soo_fpathconf,
 };
 
 int (*ifioctl)(struct socket *, u_long, void *, struct lwp *) = (void *)eopnotsupp;
@@ -263,3 +266,16 @@ soo_restart(file_t *fp)
 
 	sorestart(fp->f_socket);
 }
+
+static int
+soo_fpathconf(struct file *fp, int name, register_t *retval)
+{
+
+	switch (name) {
+	case _PC_PIPE_BUF:
+		*retval = PIPE_BUF;
+		return 0;
+	default:
+		return EINVAL;
+	}
+}

Index: src/sys/kern/vfs_vnops.c
diff -u src/sys/kern/vfs_vnops.c:1.239 src/sys/kern/vfs_vnops.c:1.240
--- src/sys/kern/vfs_vnops.c:1.239	Sat Apr 22 13:52:46 2023
+++ src/sys/kern/vfs_vnops.c	Sat Apr 22 13:52:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnops.c,v 1.239 2023/04/22 13:52:46 riastradh Exp $	*/
+/*	$NetBSD: vfs_vnops.c,v 1.240 2023/04/22 13:52:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.239 2023/04/22 13:52:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.240 2023/04/22 13:52:54 riastradh Exp $");
 
 #include "veriexec.h"
 
@@ -123,6 +123,7 @@ static int vn_mmap(struct file *, off_t 
     struct uvm_object **, int *);
 static int vn_seek(struct file *, off_t, int, off_t *, int);
 static int vn_advlock(struct file *, void *, int, struct flock *, int);
+static int vn_fpathconf(struct file *, int, register_t *);
 
 const struct fileops vnops = {
 	.fo_name = "vn",
@@ -138,6 +139,7 @@ const struct fileops vnops = {
 	.fo_mmap = vn_mmap,
 	.fo_seek = vn_seek,
 	.fo_advlock = vn_advlock,
+	.fo_fpathconf = vn_fpathconf,
 };
 
 /*
@@ -1234,6 +1236,19 @@ vn_advlock(struct file *fp, void *id, in
 	return VOP_ADVLOCK(vp, id, op, fl, flags);
 }
 
+static int
+vn_fpathconf(struct file *fp, int name, register_t *retval)
+{
+	struct vnode *const vp = fp->f_vnode;
+	int error;
+
+	vn_lock(vp, LK_SHARED | LK_RETRY);
+	error = VOP_PATHCONF(vp, name, retval);
+	VOP_UNLOCK(vp);
+
+	return error;
+}
+
 /*
  * Check that the vnode is still valid, and if so
  * acquire requested lock.

Index: src/sys/sys/file.h
diff -u src/sys/sys/file.h:1.90 src/sys/sys/file.h:1.91
--- src/sys/sys/file.h:1.90	Sat Apr 22 13:52:46 2023
+++ src/sys/sys/file.h	Sat Apr 22 13:52:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: file.h,v 1.90 2023/04/22 13:52:46 riastradh Exp $	*/
+/*	$NetBSD: file.h,v 1.91 2023/04/22 13:52:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -63,6 +63,8 @@
 #ifndef _SYS_FILE_H_
 #define	_SYS_FILE_H_
 
+#include <sys/types.h>
+
 #include <sys/fcntl.h>
 #include <sys/unistd.h>
 
@@ -98,6 +100,7 @@ struct fileops {
 	int	(*fo_seek)	(struct file *, off_t, int, off_t *, int);
 	int	(*fo_advlock)	(struct file *, void *, int, struct flock *,
 				 int);
+	int	(*fo_fpathconf)	(struct file *, int, register_t *);
 };
 
 union file_data {

Reply via email to