lseek.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/isa_defs.h>
#include <sys/sysmacros.h>
/*
* These are defined in unistd.h - but we can't include that
*/
#define SEEK_SET 0 /* Set file pointer to "offset" */
/*
* Seek on a file
*/
#if defined(_SYSCALL32_IMPL) || defined(_ILP32)
/*
* Workhorse for the 32-bit seek variants: lseek32 and llseek32
*
* 'max' represents the maximum possible representation of offset
* in the data type corresponding to lseek and llseek. It is
* MAXOFF32_T for off32_t and MAXOFFSET_T for off64_t.
* We return EOVERFLOW if we cannot represent the resulting offset
* in the data type.
* We provide support for character devices to be seeked beyond MAXOFF32_T
* by lseek. To maintain compatibility in such cases lseek passes
* the arguments carefully to lseek_common when file is not regular.
*/
static int
{
int error;
int reg;
switch (stype) {
case SEEK_SET:
goto out;
}
break;
case SEEK_CUR:
goto out;
}
goto out;
}
break;
case SEEK_END:
goto out;
}
goto out;
}
goto out;
}
break;
case SEEK_DATA:
/*
* Get and set the file pointer to the offset of the next
* data past "off"
*/
if (error) {
return (error);
/*
* The ioctl is not supported, check the supplied
* "off" is not past the end of file
*/
if (error)
return (error);
return (ENXIO);
}
return (EOVERFLOW);
return (0);
case SEEK_HOLE:
/*
* Get and set the file pointer to the offset of the next
* hole past "off"
*/
if (error) {
return (error);
/*
* ioctl is not supported, if the off is valid return
* the "virtual hole" at the end of the file.
*/
if (error)
return (error);
else
return (ENXIO);
}
return (EOVERFLOW);
return (0);
default:
goto out;
}
return (0);
}
out:
return (error);
}
{
int error;
/*
* lseek32 returns EOVERFLOW if we cannot represent the resulting
* offset from seek in a 32-bit off_t.
* The following routines are sensitive to sign extensions and
* calculations and if ever you change this make sure it works for
* special files.
*
* When VREG is not set we do the check for stype != SEEK_SET
* to send the unsigned value to lseek_common and not the sign
* extended value. (The maximum representable value is not
* checked by lseek_common for special files.)
*/
if (!error)
}
/*
* 64-bit seeks from 32-bit applications
*/
{
int error;
#if defined(_LITTLE_ENDIAN)
#else
#endif
else {
}
}
#endif /* _SYSCALL32_IMPL || _ILP32 */
#ifdef _LP64
/*
* Seek on a file.
*
* Life is almost simple again (at least until we do 128-bit files ;-)
* This is both 'lseek' and 'llseek' to a 64-bit application.
*/
{
int error;
switch (stype) {
case SEEK_CUR:
break;
case SEEK_END:
goto lseek64error;
break;
case SEEK_SET:
break;
case SEEK_DATA:
/*
* Get and set the file pointer to the offset of the next
* data past "off"
*/
if (error) {
goto lseek64error;
}
/*
* The ioctl is not supported, check the supplied off
* is not past end of file
*/
if (error)
goto lseek64error;
goto lseek64error;
}
}
return (new_off);
case SEEK_HOLE:
/*
* Get and set the file pointer to the offset of the next
* hole past "off"
*/
if (error) {
goto lseek64error;
/*
* ioctl is not supported, if the off is valid return
* the "virtual hole" at the end of the file.
*/
if (error)
goto lseek64error;
} else {
goto lseek64error;
}
}
return (new_off);
default:
goto lseek64error;
}
return (new_off);
}
}
#endif /* _LP64 */