Date: Mon, 19 Aug 2019 00:29:05 +0000 (UTC) From: Rick Macklem <rmacklem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351201 - head/sys/kern Message-ID: <201908190029.x7J0T5R6063616@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rmacklem Date: Mon Aug 19 00:29:05 2019 New Revision: 351201 URL: https://svnweb.freebsd.org/changeset/base/351201 Log: Add a vop_stdioctl() that performs a trivial FIOSEEKDATA/FIOSEEKHOLE. Without this patch, when an application performed lseek(SEEK_DATA/SEEK_HOLE) on a file in a file system that does not have its own VOP_IOCTL(), the lseek(2) fails with errno ENOTTY. This didn't seem appropriate, since ENOTTY is not listed as an error return by either the lseek(2) man page nor the POSIX draft for lseek(2). A discussion on freebsd-current@ seemed to indicate that implementing a trivial algorithm that returns the offset argument for FIOSEEKDATA and returns the file's size for FIOSEEKHOLE was the preferred fix. http://docs.FreeBSD.org/cgi/mid.cgi?CAOtMX2iiQdv1+15e1N_r7V6aCx_VqAJCTP1AW+qs3Yg7sPg9wA The Linux kernel appears to implement this trivial algorithm as well. This patch adds a vop_stdioctl() that implements this trivial algorithm. It returns errors consistent with vn_bmap_seekhole() and, as such, will still return ENOTTY for non-regular files. I have proposed a separate patch that maps errors not described by the lseek(2) man page nor POSIX draft to EINVAL. This patch is under separate review. Reviewed by: kib Relnotes: yes Differential Revision: https://reviews.freebsd.org/D21299 Modified: head/sys/kern/vfs_default.c Modified: head/sys/kern/vfs_default.c ============================================================================== --- head/sys/kern/vfs_default.c Sun Aug 18 23:44:23 2019 (r351200) +++ head/sys/kern/vfs_default.c Mon Aug 19 00:29:05 2019 (r351201) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include <sys/buf.h> #include <sys/conf.h> #include <sys/event.h> +#include <sys/filio.h> #include <sys/kernel.h> #include <sys/limits.h> #include <sys/lock.h> @@ -86,6 +87,7 @@ static int vop_stdadd_writecount(struct vop_add_writec static int vop_stdcopy_file_range(struct vop_copy_file_range_args *ap); static int vop_stdfdatasync(struct vop_fdatasync_args *ap); static int vop_stdgetpages_async(struct vop_getpages_async_args *ap); +static int vop_stdioctl(struct vop_ioctl_args *ap); /* * This vnode table stores what we want to do if the filesystem doesn't @@ -118,7 +120,7 @@ struct vop_vector default_vnodeops = { .vop_getpages_async = vop_stdgetpages_async, .vop_getwritemount = vop_stdgetwritemount, .vop_inactive = VOP_NULL, - .vop_ioctl = VOP_ENOTTY, + .vop_ioctl = vop_stdioctl, .vop_kqfilter = vop_stdkqfilter, .vop_islocked = vop_stdislocked, .vop_lock1 = vop_stdlock, @@ -1152,6 +1154,41 @@ vop_stdadd_writecount(struct vop_add_writecount_args * error = 0; } VI_UNLOCK(vp); + return (error); +} + +static int +vop_stdioctl(struct vop_ioctl_args *ap) +{ + struct vnode *vp; + struct vattr va; + off_t *offp; + int error; + + switch (ap->a_command) { + case FIOSEEKDATA: + case FIOSEEKHOLE: + vp = ap->a_vp; + error = vn_lock(vp, LK_SHARED); + if (error != 0) + return (EBADF); + if (vp->v_type == VREG) + error = VOP_GETATTR(vp, &va, ap->a_cred); + else + error = ENOTTY; + if (error == 0) { + offp = ap->a_data; + if (*offp < 0 || *offp >= va.va_size) + error = ENXIO; + else if (ap->a_command == FIOSEEKHOLE) + *offp = va.va_size; + } + VOP_UNLOCK(vp, 0); + break; + default: + error = ENOTTY; + break; + } return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908190029.x7J0T5R6063616>