Add kern_lseek() and use it instead of sys_lseek() in various compats.

I didn't touch svr4/, there's no point.

Reviewed by:	ed@, kib@
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D9366
This commit is contained in:
Edward Tomasz Napierala 2017-01-30 12:24:47 +00:00
parent ae6b6ef6cb
commit f67d6b5f12
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=312987
5 changed files with 31 additions and 78 deletions

View File

@ -209,26 +209,23 @@ cloudabi_sys_fd_replace(struct thread *td,
int
cloudabi_sys_fd_seek(struct thread *td, struct cloudabi_sys_fd_seek_args *uap)
{
struct lseek_args lseek_args = {
.fd = uap->fd,
.offset = uap->offset
};
int whence;
switch (uap->whence) {
case CLOUDABI_WHENCE_CUR:
lseek_args.whence = SEEK_CUR;
whence = SEEK_CUR;
break;
case CLOUDABI_WHENCE_END:
lseek_args.whence = SEEK_END;
whence = SEEK_END;
break;
case CLOUDABI_WHENCE_SET:
lseek_args.whence = SEEK_SET;
whence = SEEK_SET;
break;
default:
return (EINVAL);
}
return (sys_lseek(td, &lseek_args));
return (kern_lseek(td, uap->fd, uap->offset, whence));
}
/* Converts a file descriptor to a CloudABI file descriptor type. */

View File

@ -1477,12 +1477,8 @@ freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
int
ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
{
struct lseek_args nuap;
nuap.fd = uap->fd;
nuap.offset = uap->offset;
nuap.whence = uap->whence;
return (sys_lseek(td, &nuap));
return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
}
#endif
@ -1490,13 +1486,10 @@ int
freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
{
int error;
struct lseek_args ap;
off_t pos;
ap.fd = uap->fd;
ap.offset = PAIR32TO64(off_t,uap->offset);
ap.whence = uap->whence;
error = sys_lseek(td, &ap);
error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
uap->whence);
/* Expand the quad return into two parts for eax and edx */
pos = td->td_uretoff.tdu_off;
td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
@ -1593,13 +1586,10 @@ int
freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
{
int error;
struct lseek_args ap;
off_t pos;
ap.fd = uap->fd;
ap.offset = PAIR32TO64(off_t,uap->offset);
ap.whence = uap->whence;
error = sys_lseek(td, &ap);
error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
uap->whence);
/* Expand the quad return into two parts for eax and edx */
pos = *(off_t *)(td->td_retval);
td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */

View File

@ -210,31 +210,19 @@ linux_open(struct thread *td, struct linux_open_args *args)
int
linux_lseek(struct thread *td, struct linux_lseek_args *args)
{
struct lseek_args /* {
int fd;
int pad;
off_t offset;
int whence;
} */ tmp_args;
int error;
#ifdef DEBUG
if (ldebug(lseek))
printf(ARGS(lseek, "%d, %ld, %d"),
args->fdes, (long)args->off, args->whence);
#endif
tmp_args.fd = args->fdes;
tmp_args.offset = (off_t)args->off;
tmp_args.whence = args->whence;
error = sys_lseek(td, &tmp_args);
return (error);
return (kern_lseek(td, args->fdes, args->off, args->whence));
}
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int
linux_llseek(struct thread *td, struct linux_llseek_args *args)
{
struct lseek_args bsd_args;
int error;
off_t off;
@ -245,14 +233,12 @@ linux_llseek(struct thread *td, struct linux_llseek_args *args)
#endif
off = (args->olow) | (((off_t) args->ohigh) << 32);
bsd_args.fd = args->fd;
bsd_args.offset = off;
bsd_args.whence = args->whence;
if ((error = sys_lseek(td, &bsd_args)))
error = kern_lseek(td, args->fd, off, args->whence);
if (error != 0)
return (error);
if ((error = copyout(td->td_retval, args->res, sizeof (off_t))))
error = copyout(td->td_retval, args->res, sizeof(off_t));
if (error != 0)
return (error);
td->td_retval[0] = 0;

View File

@ -1806,25 +1806,25 @@ struct lseek_args {
};
#endif
int
sys_lseek(td, uap)
struct thread *td;
register struct lseek_args /* {
int fd;
int pad;
off_t offset;
int whence;
} */ *uap;
sys_lseek(struct thread *td, struct lseek_args *uap)
{
return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
}
int
kern_lseek(struct thread *td, int fd, off_t offset, int whence)
{
struct file *fp;
cap_rights_t rights;
int error;
AUDIT_ARG_FD(uap->fd);
error = fget(td, uap->fd, cap_rights_init(&rights, CAP_SEEK), &fp);
AUDIT_ARG_FD(fd);
error = fget(td, fd, cap_rights_init(&rights, CAP_SEEK), &fp);
if (error != 0)
return (error);
error = (fp->f_ops->fo_flags & DFLAG_SEEKABLE) != 0 ?
fo_seek(fp, uap->offset, uap->whence, td) : ESPIPE;
fo_seek(fp, offset, whence, td) : ESPIPE;
fdrop(fp, td);
return (error);
}
@ -1841,41 +1841,20 @@ struct olseek_args {
};
#endif
int
olseek(td, uap)
struct thread *td;
register struct olseek_args /* {
int fd;
long offset;
int whence;
} */ *uap;
olseek(struct thread *td, struct olseek_args *uap)
{
struct lseek_args /* {
int fd;
int pad;
off_t offset;
int whence;
} */ nuap;
nuap.fd = uap->fd;
nuap.offset = uap->offset;
nuap.whence = uap->whence;
return (sys_lseek(td, &nuap));
return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
}
#endif /* COMPAT_43 */
#if defined(COMPAT_FREEBSD6)
/* Version with the 'pad' argument */
int
freebsd6_lseek(td, uap)
struct thread *td;
register struct freebsd6_lseek_args *uap;
freebsd6_lseek(struct thread *td, struct freebsd6_lseek_args *uap)
{
struct lseek_args ouap;
ouap.fd = uap->fd;
ouap.offset = uap->offset;
ouap.whence = uap->whence;
return (sys_lseek(td, &ouap));
return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
}
#endif

View File

@ -135,6 +135,7 @@ int kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat);
int kern_kldunload(struct thread *td, int fileid, int flags);
int kern_linkat(struct thread *td, int fd1, int fd2, char *path1,
char *path2, enum uio_seg segflg, int follow);
int kern_lseek(struct thread *td, int fd, off_t offset, int whence);
int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
struct timeval *tptr, enum uio_seg tptrseg);
int kern_mkdirat(struct thread *td, int fd, char *path,