Module Name: src Committed By: apb Date: Fri Oct 19 16:55:22 UTC 2012
Modified Files: src/sys/compat/common: Makefile src/sys/kern: tty.c tty_ptm.c Added Files: src/sys/compat/common: tty_60.c src/sys/compat/sys: ttycom.h Log Message: Add COMPAT_60 versions of the TIOCPTMGET and TIOCPTSNAME ioctls. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/sys/compat/common/Makefile cvs rdiff -u -r0 -r1.1 src/sys/compat/common/tty_60.c cvs rdiff -u -r0 -r1.1 src/sys/compat/sys/ttycom.h cvs rdiff -u -r1.255 -r1.256 src/sys/kern/tty.c cvs rdiff -u -r1.27 -r1.28 src/sys/kern/tty_ptm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/common/Makefile diff -u src/sys/compat/common/Makefile:1.49 src/sys/compat/common/Makefile:1.50 --- src/sys/compat/common/Makefile:1.49 Sun Feb 19 17:40:46 2012 +++ src/sys/compat/common/Makefile Fri Oct 19 16:55:22 2012 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.49 2012/02/19 17:40:46 matt Exp $ +# $NetBSD: Makefile,v 1.50 2012/10/19 16:55:22 apb Exp $ LIB= compat NOPIC= # defined @@ -45,7 +45,7 @@ SRCS+= kern_time_50.c kern_select_50.c r vfs_syscalls_50.c uipc_syscalls_50.c # Compatibility code for NetBSD 6.0 -SRCS+= kern_sa_60.c +SRCS+= kern_sa_60.c tty_60.c # really, all machines where sizeof(int) != sizeof(long) (LP64) .if (${MACHINE_ARCH} != "alpha" && ${MACHINE_ARCH} != "sparc64" \ Index: src/sys/kern/tty.c diff -u src/sys/kern/tty.c:1.255 src/sys/kern/tty.c:1.256 --- src/sys/kern/tty.c:1.255 Tue Oct 2 23:10:34 2012 +++ src/sys/kern/tty.c Fri Oct 19 16:55:22 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.255 2012/10/02 23:10:34 mlelstv Exp $ */ +/* $NetBSD: tty.c,v 1.256 2012/10/19 16:55:22 apb Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.255 2012/10/02 23:10:34 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.256 2012/10/19 16:55:22 apb Exp $"); + +#include "opt_compat_netbsd.h" #include <sys/param.h> #include <sys/systm.h> @@ -93,6 +95,10 @@ __KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.25 #include <sys/module.h> #include <sys/bitops.h> +#ifdef COMPAT_60 +#include <compat/sys/ttycom.h> +#endif /* COMPAT_60 */ + static int ttnread(struct tty *); static void ttyblock(struct tty *); static void ttyecho(int, struct tty *); @@ -1363,6 +1369,11 @@ ttioctl(struct tty *tp, u_long cmd, void error = tty_set_qsize(tp, s); return error; default: +#ifdef COMPAT_60 + error = compat_60_ttioctl(tp, cmd, data, flag, l); + if (error != EPASSTHROUGH) + return error; +#endif /* COMPAT_60 */ /* We may have to load the compat module for this. */ for (;;) { rw_enter(&ttcompat_lock, RW_READER); Index: src/sys/kern/tty_ptm.c diff -u src/sys/kern/tty_ptm.c:1.27 src/sys/kern/tty_ptm.c:1.28 --- src/sys/kern/tty_ptm.c:1.27 Thu Jun 24 13:03:11 2010 +++ src/sys/kern/tty_ptm.c Fri Oct 19 16:55:22 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: tty_ptm.c,v 1.27 2010/06/24 13:03:11 hannken Exp $ */ +/* $NetBSD: tty_ptm.c,v 1.28 2012/10/19 16:55:22 apb Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -27,8 +27,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.27 2010/06/24 13:03:11 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.28 2012/10/19 16:55:22 apb Exp $"); +#include "opt_compat_netbsd.h" #include "opt_ptm.h" /* pty multiplexor driver /dev/ptm{,x} */ @@ -53,6 +54,10 @@ __KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v #include <miscfs/specfs/specdev.h> +#ifdef COMPAT_60 +#include <compat/sys/ttycom.h> +#endif /* COMPAT_60 */ + #ifdef DEBUG_PTM #define DPRINTF(a) printf a #else @@ -369,6 +374,11 @@ ptmioctl(dev_t dev, u_long cmd, void *da /* now, put the indices and names into struct ptmget */ return pty_fill_ptmget(l, newdev, cfd, sfd, data); default: +#ifdef COMPAT_60 + error = compat_60_ptmioctl(dev, cmd, data, flag, l); + if (error != EPASSTHROUGH) + return error; +#endif /* COMPAT_60 */ DPRINTF(("ptmioctl EINVAL\n")); return EINVAL; } Added files: Index: src/sys/compat/common/tty_60.c diff -u /dev/null src/sys/compat/common/tty_60.c:1.1 --- /dev/null Fri Oct 19 16:55:23 2012 +++ src/sys/compat/common/tty_60.c Fri Oct 19 16:55:22 2012 @@ -0,0 +1,114 @@ +/* $NetBSD: tty_60.c,v 1.1 2012/10/19 16:55:22 apb Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Alan Barrett + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: tty_60.c,v 1.1 2012/10/19 16:55:22 apb Exp $"); + +#if defined(_KERNEL_OPT) +#include "opt_compat_netbsd.h" +#endif + +#include <sys/types.h> + +#include <sys/conf.h> +#include <sys/errno.h> +#include <sys/systm.h> + +#include <sys/tty.h> +#include <compat/sys/ttycom.h> + +/* convert struct ptmget to struct compat_60_ptmget */ +static int +ptmget_to_ptmget60(struct ptmget *pg, struct compat_60_ptmget *pg60) +{ + memset(pg60, 0, sizeof(*pg60)); + pg60->cfd = pg->cfd; + strlcpy(pg60->cn, pg->cn, sizeof(pg60->cn)); + strlcpy(pg60->sn, pg->sn, sizeof(pg60->sn)); + if (strlen(pg->cn) >= sizeof(pg60->cn) + || strlen(pg->sn) >= sizeof(pg60->sn)) + return E2BIG; + return 0; +} + +/* Helper for compat ioctls that use struct compat_60_ptmget. */ +static int +compat_60_ptmget_ioctl(dev_t dev, u_long cmd, void *data, int flag, + struct lwp *l) +{ + int ret; + u_long newcmd; + struct ptmget pg; + const struct cdevsw *cd = cdevsw_lookup(dev); + + if (cd == NULL || cd->d_ioctl == NULL) + return ENXIO; + + switch (cmd) { + case COMPAT_60_TIOCPTMGET: newcmd = TIOCPTMGET; break; + case COMPAT_60_TIOCPTSNAME: newcmd = TIOCPTSNAME; break; + default: return ENOTTY; + } + + ret = (cd->d_ioctl)(dev, newcmd, &pg, flag, l); + if (ret != 0) + return ret; + ret = ptmget_to_ptmget60(&pg, data); + return ret; +} + +/* + * COMPAT_60 versions of ttioctl and ptmioctl. + */ +int +compat_60_ttioctl(struct tty *tp, u_long cmd, void *data, int flag, + struct lwp *l) +{ + + switch (cmd) { + case COMPAT_60_TIOCPTSNAME: + return compat_60_ptmget_ioctl(tp->t_dev, cmd, data, flag, l); + default: + return EPASSTHROUGH; + } +} + +int +compat_60_ptmioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) +{ + + switch (cmd) { + case COMPAT_60_TIOCPTMGET: + return compat_60_ptmget_ioctl(dev, cmd, data, flag, l); + default: + return EPASSTHROUGH; + } +} Index: src/sys/compat/sys/ttycom.h diff -u /dev/null src/sys/compat/sys/ttycom.h:1.1 --- /dev/null Fri Oct 19 16:55:23 2012 +++ src/sys/compat/sys/ttycom.h Fri Oct 19 16:55:22 2012 @@ -0,0 +1,66 @@ +/* $NetBSD: ttycom.h,v 1.1 2012/10/19 16:55:22 apb Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Alan Barrett + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _COMPAT_SYS_TTYCOM_H_ +#define _COMPAT_SYS_TTYCOM_H_ + +#if defined(_KERNEL_OPT) +#include "opt_compat_netbsd.h" +#include "opt_compat_netbsd32.h" +#endif + +#include <sys/types.h> +#include <sys/ioctl.h> + +#ifdef COMPAT_60 + +/* + * The cn and sn fields in struct ptmget changed size from + * char[16] to char[PATH_MAX] in NetBSD-6.99.12. + */ +struct compat_60_ptmget { + int cfd; + int sfd; + char cn[16]; + char sn[16]; +}; + +#define COMPAT_60_TIOCPTMGET _IOR('t', 70, struct compat_60_ptmget) +#define COMPAT_60_TIOCPTSNAME _IOR('t', 72, struct compat_60_ptmget) + +#ifdef _KERNEL +int compat_60_ttioctl(struct tty *, u_long, void *, int, struct lwp *); +int compat_60_ptmioctl(dev_t, u_long, void *, int, struct lwp *); +#endif + +#endif /* COMPAT_60 */ + +#endif /* !_COMPAT_SYS_TTYCOM_H_ */