From dan@kulesh.obluda.cz  Sun May 13 17:12:31 2007
Return-Path: <dan@kulesh.obluda.cz>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 0152916A402
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 13 May 2007 17:12:31 +0000 (UTC)
	(envelope-from dan@kulesh.obluda.cz)
Received: from smtp1.kolej.mff.cuni.cz (smtp1.kolej.mff.cuni.cz [195.113.24.4])
	by mx1.freebsd.org (Postfix) with ESMTP id 9DB1B13C43E
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 13 May 2007 17:12:30 +0000 (UTC)
	(envelope-from dan@kulesh.obluda.cz)
Received: from kulesh.obluda.cz (openvpn.ms.mff.cuni.cz [195.113.20.87])
	by smtp1.kolej.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l4DHCQuI059234
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 13 May 2007 19:12:28 +0200 (CEST)
	(envelope-from dan@kulesh.obluda.cz)
Received: from kulesh.obluda.cz (localhost. [127.0.0.1])
	by kulesh.obluda.cz (8.13.8/8.13.8) with ESMTP id l4DHCQaQ060155
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 13 May 2007 19:12:26 +0200 (CEST)
	(envelope-from dan@kulesh.obluda.cz)
Received: (from root@localhost)
	by kulesh.obluda.cz (8.14.1/8.13.8/Submit) id l4DHCPmg060154;
	Sun, 13 May 2007 19:12:25 +0200 (CEST)
	(envelope-from dan)
Message-Id: <200705131712.l4DHCPmg060154@kulesh.obluda.cz>
Date: Sun, 13 May 2007 19:12:25 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: tty's driver method t_ioctl() never called
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         112634
>Category:       kern
>Synopsis:       [tty] [patch] tty's driver method t_ioctl() never called
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 13 17:20:02 GMT 2007
>Closed-Date:    Wed Jul 23 14:59:29 UTC 2008
>Last-Modified:  Wed Jul 23 14:59:29 UTC 2008
>Originator:     Dan Lukes
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
Obludarium
>Environment:
System: FreeBSD kulesh.obluda.cz 6.2-STABLE FreeBSD 6.2-STABLE #0: Wed Apr 11 12:30:28 CEST 2007 dan@kulesh.obluda.cz:/usr/obj/usr/src/sys/KULESH i386
src/sys/kern/tty.c,v 1.250.2.4 2006/12/21 16:24:22


	
>Description:
On Wed Jun 30 21:38:08 2004 UTC (2 years, 10 months ago) phk commited into tty.h
new optional tty's driver supplied method - t_ioctl() with the comment:

 ====
Add t_ioctl (more about this later).
 ====

	Unfortunately, the "later" still not arrived. As far as I know, the t_ioctl()
is not called by current code. Even I run the grep for entire sys tree, 
the t_ioctl() seems to be really ignored.

	To be more interesting, there are two system drivers implementing
this driver method - digi and ucom (ucom doesn't use callback for self 
it pass the call to underlying drivers where only umodem tried to use it).

	The ioctls implemented in digi and umodem seems to be umimportant and 
other drivers doesn't implement the method at all, so nobody complained until now.

	

>How-To-Repeat:
	Wrote own tty driver with t_ioctl function. Use a printf when called. 
You will never see the output.

>Fix:

1. Call t_ioctl (unless not set) in apropriate place (tty.c diff)
	The driver routine need to return ENOIOCTL for IOCTL's not processed within 
	it (the same behavior as ttyld_ioctl() and ttioctl()).

2. as side efect of [1] the umodem.c, ucom.c and digi.c ioctl routines need to be
patched (those routines has been never called until [1] fix) - 
- routines need to return ENOIOCTL for unhandled IOCTLs instead of ENOTTY 
(umodem.c, ucom.c & digi.c diff). 



--- sys/kern/tty.c.ORIG	Fri Jan 12 03:54:46 2007
+++ sys/kern/tty.c	Sun May 13 17:01:47 2007
@@ -3255,7 +3255,9 @@
 		    dt->c_ospeed = tp->t_ospeed;
 	}
 
-	error = ttyld_ioctl(tp, cmd, data, flag, td);
+	error=(tp->t_ioctl != NULL)?tp->t_ioctl(tp, cmd, data, flag, td):ENOIOCTL;
+	if (error == ENOIOCTL)
+		error = ttyld_ioctl(tp, cmd, data, flag, td);
 	if (error == ENOIOCTL)
 		error = ttioctl(tp, cmd, data, flag);
 	ttyldoptim(tp);
--- sys/dev/usb/ucom.c.ORIG	Tue Apr 12 02:26:40 2005
+++ sys/dev/usb/ucom.c	Sun May 13 18:11:44 2007
@@ -336,7 +336,7 @@
 
 	DPRINTF(("ucomioctl: cmd = 0x%08lx\n", cmd));
 
-	error = ENOTTY;
+	error = ENOIOCTL;
 	if (sc->sc_callback->ucom_ioctl != NULL)
 		error = sc->sc_callback->ucom_ioctl(sc->sc_parent,
 						    sc->sc_portno,
--- sys/dev/usb/umodem.c.ORIG	Sun Jul 16 19:47:02 2006
+++ sys/dev/usb/umodem.c	Sun May 13 17:56:41 2007
@@ -650,12 +650,13 @@
 	case USB_SET_CM_OVER_DATA:
 		if (*(int *)data != sc->sc_cm_over_data) {
 			/* XXX change it */
+			error = EOPNOTSUPP; /* until implemented */
 		}
 		break;
 
 	default:
 		DPRINTF(("umodemioctl: unknown\n"));
-		error = ENOTTY;
+		error = ENOIOCTL;
 		break;
 	}
--- sys/dev/digi/digi.c.ORIG	Fri Feb 23 18:17:46 2007
+++ sys/dev/digi/digi.c	Sun May 13 18:00:01 2007
@@ -951,7 +951,7 @@
 		port->send_ring = (u_char)*(int *)data;
 		break;
 	default:
-		return (ENOTTY);
+		return (ENOIOCTL);
 	}
 	return (0);
 }
 


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ed 
State-Changed-When: Wed Jul 23 14:59:28 UTC 2008 
State-Changed-Why:  
Thanks for the patch, but it no longer applies with the MPSAFE TTY code 
that will be integrated next month. Because various mechanisms have been 
pushed down into the drivers (break, PPS API), ioctl's are now 
implemented inside various drivers. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112634 
>Unformatted:
