Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add COMPAT_60 versions of the TIOCPTMGET and TIOCPTSNAME...



details:   https://anonhg.NetBSD.org/src/rev/44d2d18cb794
branches:  trunk
changeset: 782171:44d2d18cb794
user:      apb <apb%NetBSD.org@localhost>
date:      Fri Oct 19 16:55:22 2012 +0000

description:
Add COMPAT_60 versions of the TIOCPTMGET and TIOCPTSNAME ioctls.

diffstat:

 sys/compat/common/Makefile |    4 +-
 sys/compat/common/tty_60.c |  114 +++++++++++++++++++++++++++++++++++++++++++++
 sys/compat/sys/ttycom.h    |   66 ++++++++++++++++++++++++++
 sys/kern/tty.c             |   15 +++++-
 sys/kern/tty_ptm.c         |   14 ++++-
 5 files changed, 207 insertions(+), 6 deletions(-)

diffs (292 lines):

diff -r 55a06ae7941b -r 44d2d18cb794 sys/compat/common/Makefile
--- a/sys/compat/common/Makefile        Fri Oct 19 16:49:49 2012 +0000
+++ b/sys/compat/common/Makefile        Fri Oct 19 16:55:22 2012 +0000
@@ -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 @@
        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" \
diff -r 55a06ae7941b -r 44d2d18cb794 sys/compat/common/tty_60.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/common/tty_60.c        Fri Oct 19 16:55:22 2012 +0000
@@ -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;
+       }
+}
diff -r 55a06ae7941b -r 44d2d18cb794 sys/compat/sys/ttycom.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/sys/ttycom.h   Fri Oct 19 16:55:22 2012 +0000
@@ -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_ */
diff -r 55a06ae7941b -r 44d2d18cb794 sys/kern/tty.c
--- a/sys/kern/tty.c    Fri Oct 19 16:49:49 2012 +0000
+++ b/sys/kern/tty.c    Fri Oct 19 16:55:22 2012 +0000
@@ -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 @@
 #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 @@
                        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);
diff -r 55a06ae7941b -r 44d2d18cb794 sys/kern/tty_ptm.c
--- a/sys/kern/tty_ptm.c        Fri Oct 19 16:49:49 2012 +0000
+++ b/sys/kern/tty_ptm.c        Fri Oct 19 16:55:22 2012 +0000
@@ -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 @@
 
 #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 @@
                /* 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;
        }



Home | Main Index | Thread Index | Old Index