tech-kern archive

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

Re: Getting the device name from a struct tty *

On Tue, Oct 15, 2013 at 01:11:40PM -0400, Mouse wrote:
> >> In a tty line discipline, I want to get the name of the tty driver
> >> instance, e.g. "dtyU0".
> In what sense is that the name of the tty driver instance?
> I'm not just being snarky; that's a real question.  Names of the dtyU0
> kind normally name device special files in /dev but nothing else - the
> kernel doesn't know anything about them.  In theory you could read
> /dev, but (a) nothing says device special files can't exist elsewhere
> and (b) you then have to decide what to do if you find other than
> exactly one device special file pointing to the device in question.
> (And, of course, (c) you may not be in a context from which reading
> /dev is feasible.)  But if that's the name you want, there may be
> little choice.

There is also no reason (in general) why there should be a /dev entry
anywhere at all.  The tty could be a cloning driver that allocates a
new minor on every open (and without any magic to create a /dev entry).

The libc ttyname() function is often implemented using a database
of known tty entries - otherwise the lookup can involve a recursive
search of /dev - which might be needed anyway if entries are dynamically
added - not sure how netbsd handles it.

I have been handed (on paper!) several hundred sheets of system call
trace from a program that was scanning a list looking for an entry
for it's current terminal - and calling ttyname() for each entry!

On SYSV we used to go through 'hoops' so that ttyname() could return
the expected /dev entry when there might be multiple /dev entries
with the same major/minor.


David Laight:

Home | Main Index | Thread Index | Old Index