[comp.unix.xenix] Help with line disciplines

shepperd@dms.UUCP (Dave Shepperd) (04/15/89)

I've written a command line editor (an interactive "screen mode" type
editor) and installed it as a line discipline in a Xenix/386 2.3.1
system and it works...mostly. I have some meaty questions about the
inner workings of the kernel that I hope someone out there can answer.

What does the kernel expect the line discipline routines to do EXACTLY?
I mean what bits in what structures does it want twiddled and, more
importantly, what bits does it want left alone? I'm concerned the most
about the l_open, l_close and the l_ioctl functions. I have made
assumptions about what the others do and apparently guessed right
because the editor works. This question may be best answered by suggesting
a book on the subject.

The problems I am having are when multiple streams are established to
the terminal. It seems some utilities call l_ioctl before calling l_open
(such as stty), while others call l_open before calling l_ioctl (such as
shl). I want the ld to keep separate structures for each stream for
edit functions and input history so it's necessary to distinguish between
them. It's not clear to me how to do that.

Is it always correct for the l_open and l_ioctl routines to assume the
u structure has meaningful data in it (or that it is even accessible)?

How does a driver, given the process group number, access the list of
processes belonging to that group? (ps does it somehow). I believe I will
need to access this list at interrupt time.
-- 

Dave Shepperd.	    shepperd@dms.UUCP or weitek!dms!shepperd
Atari Games Corporation, Sycamore Drive, Milpitas CA 95035.
(Arcade Video Game Manufacturer, NOT Atari Corp. ST manufacturer).

ka@june.cs.washington.edu (Kenneth Almquist) (04/16/89)

Unfortunately, line disciplines are not well documented.  As I recall,
l_open is called every time an open system call is done on the device,
and l_close is called when a close system call is done and nothing else
has the device open.  When a program is run from the shell, the tty is
not opened (instead it inherits its file descriptors from the shell) so
the l_open routine is not called.

I'm not sure it is "correct" to access the u structure from within a
device driver, but it should word as the routine accessing the structure
was invoked from a system call rather than an interrupt.

To find all the processes in a process group, you have to search the
process table.  This is an array of proc structures (defined in sys/proc.h)
named proc.  There is also a routine (gsignal, I think) that will send
a signal to all processes in a process group.
				Kenneth Almquist

steve@nuchat.UUCP (Steve Nuchia) (04/17/89)

In article <763@dms.UUCP> shepperd@dms.UUCP (Dave Shepperd) writes:
>What does the kernel expect the line discipline routines to do EXACTLY?
>I mean what bits in what structures does it want twiddled and, more
>importantly, what bits does it want left alone? I'm concerned the most

This is not documented in any obvious place, and as far as I know
isn't *documented* anywhere.  It can be deduced within the limits
of the correctness of the examples by examining existing drivers
and LD code, if you have access and choose to use it.

>about the l_open, l_close and the l_ioctl functions. I have made
>assumptions about what the others do and apparently guessed right
>because the editor works. This question may be best answered by suggesting
>a book on the subject.

If you find one PLEASE let me know.  I have every book that even
mentions Unix driver writing, and LD interfacing is never covered
in any kind of detail.  I've had to do pretty much the same
reverse-engineering job you did for my 286/386 serial driver.

>Is it always correct for the l_open and l_ioctl routines to assume the
>u structure has meaningful data in it (or that it is even accessible)?

Yes.  The u area is nailed down and correct for anything that
isn't called at interrupt time.  Unless something in streams
breaks this?  I haven't played with stream from the inside yet.

>How does a driver, given the process group number, access the list of
>processes belonging to that group? (ps does it somehow). I believe I will
>need to access this list at interrupt time.

The only thing you can do to the process group is send a signal
to all members; the signal routine has a loop over the process
table that tickles every process that matches.  If you want
to do something else (what? sounds dangerous) you need to
loop similarly.

-- 
Steve Nuchia	      South Coast Computing Services
uunet!nuchat!steve    POB 890952  Houston, Texas  77289
(713) 964 2462	      Consultation & Systems, Support for PD Software.

paul@prcrs.UUCP (Paul Hite) (04/18/89)

In article <6511@nuchat.UUCP>, steve@nuchat.UUCP (Steve Nuchia) writes:
> In article <763@dms.UUCP> shepperd@dms.UUCP (Dave Shepperd) writes:
> >What does the kernel expect the line discipline routines to do EXACTLY?
> >                          This question may be best answered by suggesting
> >a book on the subject.
> 
> If you find one PLEASE let me know.  I have every book that even
> mentions Unix driver writing, and LD interfacing is never covered
> in any kind of detail.  

Well Steve, I'll bet you've overlooked a book or two.  I  have the 
following two books which I obtained from AT&T:

UNIX System V, Release 3 Block and Character Interface (BCI)  Driver
Development Guide  (select code 307-191)

and its companion:

UNIX System V, Release 3 Block and Character Interface (BCI)  Driver
Reference Manual  (select code 307-192)

Both books are 8.5 by 11.  Together they are bigger than most phone books.
They are pricey (about $150 for the pair as I remember) but they are worth
it.

Chapter 7 is about the TTY subsystem and there is much info on LD.  Contents:

Line Disciplines					7-4
Line Discipline Zero					7-5
Writing Line Disciplines				7-7
Line Discipline Functions Calling Sequences	  	7-9
	ttread and ttwrite				7-10
	ttioctl and ttin				7-11
	ttout, ttxput, and tttimeo			7-12
	ttiocom						7-13
	ttyflush, ttinit, ttywait, cannon, ttrstrt	7-15

I've never done anything with a driver besides look at it, so I left
Dave's other questions for the real experts.  But I do reccommend these
books.  I got them by calling AT&T but I don't have the number anymore.

Paul Hite   PRC Realty Systems  McLean,Va   uunet!prcrs!paul    (703) 556-2243
                      DOS is a four letter word!