Date: Wed, 3 Mar 2010 16:18:05 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r204638 - head/sys/kern Message-ID: <201003031618.o23GI5Pr000438@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Wed Mar 3 16:18:04 2010 New Revision: 204638 URL: http://svn.freebsd.org/changeset/base/204638 Log: Allow lseek(SEEK_END) to work on disk devices by using the DIOCGMEDIASIZE to determine the media size. Submitted by: nox MFC after: 1 week Modified: head/sys/kern/vfs_syscalls.c Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Wed Mar 3 16:06:43 2010 (r204637) +++ head/sys/kern/vfs_syscalls.c Wed Mar 3 16:18:04 2010 (r204638) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/bio.h> #include <sys/buf.h> +#include <sys/disk.h> #include <sys/sysent.h> #include <sys/malloc.h> #include <sys/mount.h> @@ -1920,7 +1921,7 @@ lseek(td, uap) struct file *fp; struct vnode *vp; struct vattr vattr; - off_t offset; + off_t offset, size; int error, noneg; int vfslocked; @@ -1951,6 +1952,15 @@ lseek(td, uap) VOP_UNLOCK(vp, 0); if (error) break; + + /* + * If the file references a disk device, then fetch + * the media size and use that to determine the ending + * offset. + */ + if (vattr.va_size == 0 && vp->v_type == VCHR && + fo_ioctl(fp, DIOCGMEDIASIZE, &size, cred, td) == 0) + vattr.va_size = size; if (noneg && (vattr.va_size > OFF_MAX || (offset > 0 && vattr.va_size > OFF_MAX - offset))) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003031618.o23GI5Pr000438>