Subject: ptyfs fully working now...
To: None <>
From: Christos Zoulas <>
List: tech-kern
Date: 11/08/2004 15:04:52

This is work in progress for a ptyfs implementation. To use it, untar the
tar file apply the patch, build a new kernel and reboot. You can build and
modload the ptyfs lkm, and then mkdir /dev/pts, mount_ptyfs ptyfs /dev/pts.

Why I did this:

1. I wanted to get rid of all the tty and pty files in /dev
2. It is needed for compat_linux (new matlab)
3. I wanted to learn more about filesystems

Everything seems to work now, and I am planning to commit this shortly.
Please let me know if you have any problems with this.
The package is on

Implementation notes:

1. I split the code in tty_pty.c into:
	tty_pty.c -- basic pty code.
	tty_ptm.c -- /dev/ptm /dev/ptmx
	tty_bsdpty.c -- /dev/ptyXX /dev/ttyXX pty allocation code for ptmx
	sys/pty.h -- variables shared between ptyfs and the rest.
2. There are two functions that describe the interface for ptm to create
   ptys (in sys/pty.h). A makename function and an allocvp function. Both
   the bsdpty and the ptyfs implementation use them. Once you mount the
   ptyfs filesystem, it replaces the bsdpty implementation with the ptyfs
   one, and once you unmount it, it puts back the original.
3. I wanted the old bsd ptys to co-exist with /dev/pts. For that when ptyfs
   starts up, it will copy the permissions from /dev/ptyXX and /dev/ttyXX
   for its nodes. 
4. I did not like the way ttyname() worked with looking up the db file,
   so I let the ioctl to find the pty name work on the slave too. Now
   ttyname() will do the ioctl first to find the ttyname. If that fails,
   then it will lookup in the db. This is a lot faster in the regular
   case these days which is ptys. It is also silly to have entries for
   all the ptys in /etc/ttys. You can now remove them, and the code
   will take up the last + 1 slot for each pty (for either the old
   or the new ptys).
5. Most 3rd party programs already DTRT with pty names that look like
   /dev/pts/n, and they will just work. The order of entries in w(1)
   looks mangled because pts/N sorts before ttyXX.
   Utility programs such as w(1) print the pty short names as pN where
   N is the minor number of the pty.
6. The ioctl to retrieve the pty name and file descriptor returned the
   names of the master and slave parts and the fd's associated with them.
   Under ptyfs, there is no filesystem node for the master portion, only
   the slave one. I don't think that we should create one for the master
   side. I populate the structure with /dev/null for now.
7. Kernels need COMPAT_BSDPTY to be able to allocated old style /dev/ttyXX
   ptys using /dev/ptm. Regular pty allocation will work.