17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*da6c28aaSamw * Common Development and Distribution License (the "License").
6*da6c28aaSamw * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*da6c28aaSamw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
387c478bd9Sstevel@tonic-gate #include <sys/cred.h>
397c478bd9Sstevel@tonic-gate #include <sys/systm.h>
407c478bd9Sstevel@tonic-gate #include <sys/errno.h>
417c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
427c478bd9Sstevel@tonic-gate #include <sys/file.h>
437c478bd9Sstevel@tonic-gate #include <sys/debug.h>
447c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
457c478bd9Sstevel@tonic-gate #include <sys/filio.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate * These are defined in unistd.h - but we can't include that
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate #define SEEK_SET 0 /* Set file pointer to "offset" */
517c478bd9Sstevel@tonic-gate #define SEEK_CUR 1 /* Set file pointer to current plus "offset" */
527c478bd9Sstevel@tonic-gate #define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
537c478bd9Sstevel@tonic-gate #define SEEK_DATA 3 /* Set file pointer to next data past offset */
547c478bd9Sstevel@tonic-gate #define SEEK_HOLE 4 /* Set file pointer to next hole past offset */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * Seek on a file
587c478bd9Sstevel@tonic-gate */
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL) || defined(_ILP32)
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate * Workhorse for the 32-bit seek variants: lseek32 and llseek32
637c478bd9Sstevel@tonic-gate *
647c478bd9Sstevel@tonic-gate * 'max' represents the maximum possible representation of offset
657c478bd9Sstevel@tonic-gate * in the data type corresponding to lseek and llseek. It is
667c478bd9Sstevel@tonic-gate * MAXOFF32_T for off32_t and MAXOFFSET_T for off64_t.
677c478bd9Sstevel@tonic-gate * We return EOVERFLOW if we cannot represent the resulting offset
687c478bd9Sstevel@tonic-gate * in the data type.
697c478bd9Sstevel@tonic-gate * We provide support for character devices to be seeked beyond MAXOFF32_T
707c478bd9Sstevel@tonic-gate * by lseek. To maintain compatibility in such cases lseek passes
717c478bd9Sstevel@tonic-gate * the arguments carefully to lseek_common when file is not regular.
727c478bd9Sstevel@tonic-gate * (/dev/kmem is a good example of a > 2Gbyte seek!)
737c478bd9Sstevel@tonic-gate */
747c478bd9Sstevel@tonic-gate static int
lseek32_common(file_t * fp,int stype,offset_t off,offset_t max,offset_t * retoff)757c478bd9Sstevel@tonic-gate lseek32_common(file_t *fp, int stype, offset_t off, offset_t max,
767c478bd9Sstevel@tonic-gate offset_t *retoff)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate vnode_t *vp;
797c478bd9Sstevel@tonic-gate struct vattr vattr;
807c478bd9Sstevel@tonic-gate int error;
817c478bd9Sstevel@tonic-gate u_offset_t noff;
827c478bd9Sstevel@tonic-gate offset_t curoff, newoff;
837c478bd9Sstevel@tonic-gate int reg;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate vp = fp->f_vnode;
867c478bd9Sstevel@tonic-gate reg = (vp->v_type == VREG);
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate curoff = fp->f_offset;
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate switch (stype) {
917c478bd9Sstevel@tonic-gate case SEEK_SET:
927c478bd9Sstevel@tonic-gate noff = (u_offset_t)off;
937c478bd9Sstevel@tonic-gate if (reg && noff > max) {
947c478bd9Sstevel@tonic-gate error = EINVAL;
957c478bd9Sstevel@tonic-gate goto out;
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate break;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate case SEEK_CUR:
1007c478bd9Sstevel@tonic-gate if (reg && off > (max - curoff)) {
1017c478bd9Sstevel@tonic-gate error = EOVERFLOW;
1027c478bd9Sstevel@tonic-gate goto out;
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate noff = (u_offset_t)(off + curoff);
1057c478bd9Sstevel@tonic-gate if (reg && noff > max) {
1067c478bd9Sstevel@tonic-gate error = EINVAL;
1077c478bd9Sstevel@tonic-gate goto out;
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate break;
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate case SEEK_END:
1127c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
113*da6c28aaSamw if (error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL)) {
1147c478bd9Sstevel@tonic-gate goto out;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate if (reg && (off > (max - (offset_t)vattr.va_size))) {
1177c478bd9Sstevel@tonic-gate error = EOVERFLOW;
1187c478bd9Sstevel@tonic-gate goto out;
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate noff = (u_offset_t)(off + (offset_t)vattr.va_size);
1217c478bd9Sstevel@tonic-gate if (reg && noff > max) {
1227c478bd9Sstevel@tonic-gate error = EINVAL;
1237c478bd9Sstevel@tonic-gate goto out;
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate break;
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate case SEEK_DATA:
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate * Get and set the file pointer to the offset of the next
1307c478bd9Sstevel@tonic-gate * data past "off"
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate noff = (u_offset_t)off;
1337c478bd9Sstevel@tonic-gate error = VOP_IOCTL(vp, _FIO_SEEK_DATA, (intptr_t)(&noff),
134*da6c28aaSamw FKIOCTL, kcred, NULL, NULL);
1357c478bd9Sstevel@tonic-gate if (error) {
1367c478bd9Sstevel@tonic-gate if (error != ENOTTY)
1377c478bd9Sstevel@tonic-gate return (error);
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * The ioctl is not supported, check the supplied
1407c478bd9Sstevel@tonic-gate * "off" is not past the end of file
1417c478bd9Sstevel@tonic-gate */
1427c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
143*da6c28aaSamw error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL);
1447c478bd9Sstevel@tonic-gate if (error)
1457c478bd9Sstevel@tonic-gate return (error);
1467c478bd9Sstevel@tonic-gate if (noff >= (u_offset_t)vattr.va_size)
1477c478bd9Sstevel@tonic-gate return (ENXIO);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate if (reg && (noff > max))
1507c478bd9Sstevel@tonic-gate return (EOVERFLOW);
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate fp->f_offset = (offset_t)noff;
1537c478bd9Sstevel@tonic-gate (*retoff) = (offset_t)noff;
1547c478bd9Sstevel@tonic-gate return (0);
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate case SEEK_HOLE:
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate * Get and set the file pointer to the offset of the next
1597c478bd9Sstevel@tonic-gate * hole past "off"
1607c478bd9Sstevel@tonic-gate */
1617c478bd9Sstevel@tonic-gate noff = (u_offset_t)off;
1627c478bd9Sstevel@tonic-gate error = VOP_IOCTL(vp, _FIO_SEEK_HOLE, (intptr_t)(&noff),
163*da6c28aaSamw FKIOCTL, kcred, NULL, NULL);
1647c478bd9Sstevel@tonic-gate if (error) {
1657c478bd9Sstevel@tonic-gate if (error != ENOTTY)
1667c478bd9Sstevel@tonic-gate return (error);
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * ioctl is not supported, if the off is valid return
1697c478bd9Sstevel@tonic-gate * the "virtual hole" at the end of the file.
1707c478bd9Sstevel@tonic-gate */
1717c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
172*da6c28aaSamw error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL);
1737c478bd9Sstevel@tonic-gate if (error)
1747c478bd9Sstevel@tonic-gate return (error);
1757c478bd9Sstevel@tonic-gate if (off < (offset_t)vattr.va_size)
1767c478bd9Sstevel@tonic-gate noff = (u_offset_t)vattr.va_size;
1777c478bd9Sstevel@tonic-gate else
1787c478bd9Sstevel@tonic-gate return (ENXIO);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate if (reg && (noff > max))
1817c478bd9Sstevel@tonic-gate return (EOVERFLOW);
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate fp->f_offset = (offset_t)noff;
1847c478bd9Sstevel@tonic-gate (*retoff) = (offset_t)noff;
1857c478bd9Sstevel@tonic-gate return (0);
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate default:
1887c478bd9Sstevel@tonic-gate error = EINVAL;
1897c478bd9Sstevel@tonic-gate goto out;
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate ASSERT((reg && noff <= max) || !reg);
1937c478bd9Sstevel@tonic-gate newoff = (offset_t)noff;
194*da6c28aaSamw if ((error = VOP_SEEK(vp, curoff, &newoff, NULL)) == 0) {
1957c478bd9Sstevel@tonic-gate fp->f_offset = newoff;
1967c478bd9Sstevel@tonic-gate (*retoff) = newoff;
1977c478bd9Sstevel@tonic-gate return (0);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate out:
2007c478bd9Sstevel@tonic-gate return (error);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate off32_t
lseek32(int32_t fdes,off32_t off,int32_t stype)2047c478bd9Sstevel@tonic-gate lseek32(int32_t fdes, off32_t off, int32_t stype)
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate file_t *fp;
2077c478bd9Sstevel@tonic-gate int error;
2087c478bd9Sstevel@tonic-gate offset_t retoff;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate if ((fp = getf(fdes)) == NULL)
2117c478bd9Sstevel@tonic-gate return ((off32_t)set_errno(EBADF));
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate * lseek32 returns EOVERFLOW if we cannot represent the resulting
2157c478bd9Sstevel@tonic-gate * offset from seek in a 32-bit off_t.
2167c478bd9Sstevel@tonic-gate * The following routines are sensitive to sign extensions and
2177c478bd9Sstevel@tonic-gate * calculations and if ever you change this make sure it works for
2187c478bd9Sstevel@tonic-gate * special files.
2197c478bd9Sstevel@tonic-gate *
2207c478bd9Sstevel@tonic-gate * When VREG is not set we do the check for stype != SEEK_SET
2217c478bd9Sstevel@tonic-gate * to send the unsigned value to lseek_common and not the sign
2227c478bd9Sstevel@tonic-gate * extended value. (The maximum representable value is not
2237c478bd9Sstevel@tonic-gate * checked by lseek_common for special files.)
2247c478bd9Sstevel@tonic-gate */
2257c478bd9Sstevel@tonic-gate if (fp->f_vnode->v_type == VREG || stype != SEEK_SET)
2267c478bd9Sstevel@tonic-gate error = lseek32_common(fp, stype, (offset_t)off,
2277c478bd9Sstevel@tonic-gate (offset_t)MAXOFF32_T, &retoff);
2287c478bd9Sstevel@tonic-gate else if (stype == SEEK_SET)
2297c478bd9Sstevel@tonic-gate error = lseek32_common(fp, stype, (offset_t)(uint_t)off,
2307c478bd9Sstevel@tonic-gate (offset_t)(uint_t)UINT_MAX, &retoff);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate releasef(fdes);
2337c478bd9Sstevel@tonic-gate if (!error)
2347c478bd9Sstevel@tonic-gate return ((off32_t)retoff);
2357c478bd9Sstevel@tonic-gate return ((off32_t)set_errno(error));
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate * 64-bit seeks from 32-bit applications
2407c478bd9Sstevel@tonic-gate */
2417c478bd9Sstevel@tonic-gate offset_t
llseek32(int32_t fdes,uint32_t off1,uint32_t off2,int stype)2427c478bd9Sstevel@tonic-gate llseek32(int32_t fdes, uint32_t off1, uint32_t off2, int stype)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate file_t *fp;
2457c478bd9Sstevel@tonic-gate int error;
2467c478bd9Sstevel@tonic-gate offset_t retoff;
2477c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
2487c478bd9Sstevel@tonic-gate offset_t off = ((u_offset_t)off2 << 32) | (u_offset_t)off1;
2497c478bd9Sstevel@tonic-gate #else
2507c478bd9Sstevel@tonic-gate offset_t off = ((u_offset_t)off1 << 32) | (u_offset_t)off2;
2517c478bd9Sstevel@tonic-gate #endif
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate if ((fp = getf(fdes)) == NULL)
2547c478bd9Sstevel@tonic-gate error = EBADF;
2557c478bd9Sstevel@tonic-gate else {
2567c478bd9Sstevel@tonic-gate error = lseek32_common(fp, stype, off, MAXOFFSET_T, &retoff);
2577c478bd9Sstevel@tonic-gate releasef(fdes);
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate return (error ? (offset_t)set_errno(error) : retoff);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL || _ILP32 */
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate #ifdef _LP64
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate * Seek on a file.
2677c478bd9Sstevel@tonic-gate *
2687c478bd9Sstevel@tonic-gate * Life is almost simple again (at least until we do 128-bit files ;-)
2697c478bd9Sstevel@tonic-gate * This is both 'lseek' and 'llseek' to a 64-bit application.
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate off_t
lseek64(int fdes,off_t off,int stype)2727c478bd9Sstevel@tonic-gate lseek64(int fdes, off_t off, int stype)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate file_t *fp;
2757c478bd9Sstevel@tonic-gate vnode_t *vp;
2767c478bd9Sstevel@tonic-gate struct vattr vattr;
2777c478bd9Sstevel@tonic-gate int error;
2787c478bd9Sstevel@tonic-gate off_t old_off;
2797c478bd9Sstevel@tonic-gate offset_t new_off;
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate if ((fp = getf(fdes)) == NULL)
2827c478bd9Sstevel@tonic-gate return ((off_t)set_errno(EBADF));
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate vp = fp->f_vnode;
2857c478bd9Sstevel@tonic-gate new_off = off;
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate switch (stype) {
2887c478bd9Sstevel@tonic-gate case SEEK_CUR:
2897c478bd9Sstevel@tonic-gate new_off += fp->f_offset;
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate case SEEK_END:
2937c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
294*da6c28aaSamw if ((error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL)) != 0)
2957c478bd9Sstevel@tonic-gate goto lseek64error;
2967c478bd9Sstevel@tonic-gate new_off += vattr.va_size;
2977c478bd9Sstevel@tonic-gate break;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate case SEEK_SET:
3007c478bd9Sstevel@tonic-gate break;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate case SEEK_DATA:
3037c478bd9Sstevel@tonic-gate /*
3047c478bd9Sstevel@tonic-gate * Get and set the file pointer to the offset of the next
3057c478bd9Sstevel@tonic-gate * data past "off"
3067c478bd9Sstevel@tonic-gate */
3077c478bd9Sstevel@tonic-gate new_off = (offset_t)off;
3087c478bd9Sstevel@tonic-gate error = VOP_IOCTL(vp, _FIO_SEEK_DATA, (intptr_t)(&new_off),
309*da6c28aaSamw FKIOCTL, kcred, NULL, NULL);
3107c478bd9Sstevel@tonic-gate if (error) {
3117c478bd9Sstevel@tonic-gate if (error != ENOTTY) {
3127c478bd9Sstevel@tonic-gate goto lseek64error;
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate * The ioctl is not supported, check the supplied off
3167c478bd9Sstevel@tonic-gate * is not past end of file
3177c478bd9Sstevel@tonic-gate */
3187c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
319*da6c28aaSamw error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL);
3207c478bd9Sstevel@tonic-gate if (error)
3217c478bd9Sstevel@tonic-gate goto lseek64error;
3227c478bd9Sstevel@tonic-gate if (new_off >= (offset_t)vattr.va_size) {
3237c478bd9Sstevel@tonic-gate error = ENXIO;
3247c478bd9Sstevel@tonic-gate goto lseek64error;
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate fp->f_offset = new_off;
3287c478bd9Sstevel@tonic-gate releasef(fdes);
3297c478bd9Sstevel@tonic-gate return (new_off);
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate case SEEK_HOLE:
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate * Get and set the file pointer to the offset of the next
3347c478bd9Sstevel@tonic-gate * hole past "off"
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate new_off = off;
3377c478bd9Sstevel@tonic-gate error = VOP_IOCTL(vp, _FIO_SEEK_HOLE, (intptr_t)(&new_off),
338*da6c28aaSamw FKIOCTL, kcred, NULL, NULL);
3397c478bd9Sstevel@tonic-gate if (error) {
3407c478bd9Sstevel@tonic-gate if (error != ENOTTY)
3417c478bd9Sstevel@tonic-gate goto lseek64error;
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate * ioctl is not supported, if the off is valid return
3447c478bd9Sstevel@tonic-gate * the "virtual hole" at the end of the file.
3457c478bd9Sstevel@tonic-gate */
3467c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE;
347*da6c28aaSamw error = VOP_GETATTR(vp, &vattr, 0, fp->f_cred, NULL);
3487c478bd9Sstevel@tonic-gate if (error)
3497c478bd9Sstevel@tonic-gate goto lseek64error;
3507c478bd9Sstevel@tonic-gate if (off < (offset_t)vattr.va_size) {
3517c478bd9Sstevel@tonic-gate new_off = (offset_t)vattr.va_size;
3527c478bd9Sstevel@tonic-gate } else {
3537c478bd9Sstevel@tonic-gate error = ENXIO;
3547c478bd9Sstevel@tonic-gate goto lseek64error;
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate fp->f_offset = new_off;
3587c478bd9Sstevel@tonic-gate releasef(fdes);
3597c478bd9Sstevel@tonic-gate return (new_off);
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate default:
3627c478bd9Sstevel@tonic-gate error = EINVAL;
3637c478bd9Sstevel@tonic-gate goto lseek64error;
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate old_off = fp->f_offset;
367*da6c28aaSamw if ((error = VOP_SEEK(vp, old_off, &new_off, NULL)) == 0) {
3687c478bd9Sstevel@tonic-gate fp->f_offset = new_off;
3697c478bd9Sstevel@tonic-gate releasef(fdes);
3707c478bd9Sstevel@tonic-gate return (new_off);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate lseek64error:
3747c478bd9Sstevel@tonic-gate releasef(fdes);
3757c478bd9Sstevel@tonic-gate return ((off_t)set_errno(error));
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate #endif /* _LP64 */
378