diff options
author | Ed Schouten <ed@FreeBSD.org> | 2008-08-20 08:31:58 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2008-08-20 08:31:58 +0000 |
commit | bc093719ca478fe10b938cef32c30b528042cbcd (patch) | |
tree | bd0c08a66997254385160ce71ea32029b99f99f9 /usr.bin/fstat/fstat.c | |
parent | b14f19cf9742655c453d9c1dd672393c31080af4 (diff) | |
download | src-bc093719ca478fe10b938cef32c30b528042cbcd.tar.gz src-bc093719ca478fe10b938cef32c30b528042cbcd.zip |
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
Notes
Notes:
svn path=/head/; revision=181905
Diffstat (limited to 'usr.bin/fstat/fstat.c')
-rw-r--r-- | usr.bin/fstat/fstat.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 886c3bb4746c..6ed707681d4c 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include <sys/un.h> #include <sys/unpcb.h> #include <sys/sysctl.h> +#include <sys/tty.h> #include <sys/filedesc.h> #include <sys/queue.h> #define _WANT_FILE @@ -154,6 +155,7 @@ int devfs_filestat(struct vnode *vp, struct filestat *fsp); char *getmnton(struct mount *m); void pipetrans(struct pipe *pi, int i, int flag); void socktrans(struct socket *sock, int i); +void ptstrans(struct tty *tp, int i, int flag); void getinetproto(int number); int getfname(const char *filename); void usage(void); @@ -411,6 +413,12 @@ dofiles(struct kinfo_proc *kp) vtrans(file.f_vnode, i, file.f_flag); } #endif +#ifdef DTYPE_PTS + else if (file.f_type == DTYPE_PTS) { + if (checkfile == 0) + ptstrans(file.f_data, i, file.f_flag); + } +#endif else { dprintf(stderr, "unknown file type %d for file %d of pid %d\n", @@ -887,6 +895,50 @@ bad: printf("* error\n"); } +void +ptstrans(struct tty *tp, int i, int flag) +{ + struct tty tty; + char *name; + char rw[3]; + dev_t rdev; + + PREFIX(i); + + /* Obtain struct tty. */ + if (!KVM_READ(tp, &tty, sizeof(struct tty))) { + dprintf(stderr, "can't read tty at %p\n", (void *)tp); + goto bad; + } + + /* Figure out the device name. */ + name = kdevtoname(tty.t_dev); + if (name == NULL) { + dprintf(stderr, "can't determine tty name at %p\n", (void *)tp); + goto bad; + } + + rw[0] = '\0'; + if (flag & FREAD) + strcat(rw, "r"); + if (flag & FWRITE) + strcat(rw, "w"); + + printf("* pseudo-terminal master "); + if (nflg || !name) { + rdev = dev2udev(tty.t_dev); + printf("%10d,%-2d", major(rdev), minor(rdev)); + } else { + printf("%10s", name); + } + printf(" %2s\n", rw); + + free(name); + + return; +bad: + printf("* error\n"); +} /* * Read the cdev structure in the kernel in order to work out the |