Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys file(9): New fo_fpathconf operation.
details: https://anonhg.NetBSD.org/src/rev/69434b3fe130
branches: trunk
changeset: 374414:69434b3fe130
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Apr 22 13:52:54 2023 +0000
description:
file(9): New fo_fpathconf operation.
XXX kernel revbump -- struct fileops API and ABI change
diffstat:
sys/kern/kern_event.c | 13 +++++++++++--
sys/kern/sys_descrip.c | 40 ++++++++++------------------------------
sys/kern/sys_pipe.c | 19 +++++++++++++++++--
sys/kern/sys_socket.c | 20 ++++++++++++++++++--
sys/kern/vfs_vnops.c | 19 +++++++++++++++++--
sys/sys/file.h | 5 ++++-
6 files changed, 77 insertions(+), 39 deletions(-)
diffs (truncated from 302 to 300 lines):
diff -r fb8a18535c6e -r 69434b3fe130 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/kern/kern_event.c Sat Apr 22 13:52:54 2023 +0000
@@ -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
diff -r fb8a18535c6e -r 69434b3fe130 sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/kern/sys_descrip.c Sat Apr 22 13:52:54 2023 +0000
@@ -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;
}
/*
diff -r fb8a18535c6e -r 69434b3fe130 sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/kern/sys_pipe.c Sat Apr 22 13:52:54 2023 +0000
@@ -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)
{
diff -r fb8a18535c6e -r 69434b3fe130 sys/kern/sys_socket.c
--- a/sys/kern/sys_socket.c Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/kern/sys_socket.c Sat Apr 22 13:52:54 2023 +0000
@@ -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 @@
#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;
+ }
+}
diff -r fb8a18535c6e -r 69434b3fe130 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/kern/vfs_vnops.c Sat Apr 22 13:52:54 2023 +0000
@@ -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.
diff -r fb8a18535c6e -r 69434b3fe130 sys/sys/file.h
--- a/sys/sys/file.h Sat Apr 22 13:52:46 2023 +0000
+++ b/sys/sys/file.h Sat Apr 22 13:52:54 2023 +0000
@@ -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 *);
};
Home |
Main Index |
Thread Index |
Old Index