FreeBSD kernel kern code
tty_pts.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/condvar.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/poll.h>
#include <sys/proc.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/serial.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/ttycom.h>
#include <sys/uio.h>
#include <sys/user.h>
#include <machine/stdarg.h>
Include dependency graph for tty_pts.c:

Go to the source code of this file.

Data Structures

struct  pts_softc
 

Macros

#define PTS_COMPAT
 
#define PTS_EXTERNAL
 
#define PTS_LINUX
 
#define PTS_PKT   0x1 /* Packet mode. */
 
#define PTS_FINISHED   0x2 /* Return errors on read()/write(). */
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_PTS, "pts", "pseudo tty device")
 
static int ptsdev_read (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int ptsdev_write (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int ptsdev_ioctl (struct file *fp, u_long cmd, void *data, struct ucred *active_cred, struct thread *td)
 
static int ptsdev_poll (struct file *fp, int events, struct ucred *active_cred, struct thread *td)
 
static void pts_kqops_read_detach (struct knote *kn)
 
static int pts_kqops_read_event (struct knote *kn, long hint)
 
static void pts_kqops_write_detach (struct knote *kn)
 
static int pts_kqops_write_event (struct knote *kn, long hint)
 
static int ptsdev_kqfilter (struct file *fp, struct knote *kn)
 
static int ptsdev_stat (struct file *fp, struct stat *sb, struct ucred *active_cred)
 
static int ptsdev_close (struct file *fp, struct thread *td)
 
static int ptsdev_fill_kinfo (struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 
static void ptsdrv_outwakeup (struct tty *tp)
 
static void ptsdrv_inwakeup (struct tty *tp)
 
static int ptsdrv_open (struct tty *tp)
 
static void ptsdrv_close (struct tty *tp)
 
static void ptsdrv_pktnotify (struct tty *tp, char event)
 
static void ptsdrv_free (void *softc)
 
int pts_alloc (int fflags, struct thread *td, struct file *fp)
 
int pts_alloc_external (int fflags, struct thread *td, struct file *fp, struct cdev *dev, const char *name)
 
int sys_posix_openpt (struct thread *td, struct posix_openpt_args *uap)
 
static void pts_init (void *unused)
 
 SYSINIT (pts, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, pts_init, NULL)
 

Variables

static struct unrhdr * pts_pool
 
static struct filterops pts_kqops_read
 
static struct filterops pts_kqops_write
 
static struct fileops ptsdev_ops
 
static struct ttydevsw pts_class
 

Macro Definition Documentation

◆ PTS_COMPAT

#define PTS_COMPAT

Definition at line 36 of file tty_pts.c.

◆ PTS_EXTERNAL

#define PTS_EXTERNAL

Definition at line 38 of file tty_pts.c.

◆ PTS_FINISHED

#define PTS_FINISHED   0x2 /* Return errors on read()/write(). */

Definition at line 94 of file tty_pts.c.

◆ PTS_LINUX

#define PTS_LINUX

Definition at line 40 of file tty_pts.c.

◆ PTS_PKT

#define PTS_PKT   0x1 /* Packet mode. */

Definition at line 93 of file tty_pts.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_PTS  ,
"pts"  ,
"pseudo tty device  
)
static

◆ pts_alloc()

int pts_alloc ( int  fflags,
struct thread *  td,
struct file *  fp 
)

Definition at line 738 of file tty_pts.c.

References alloc_unr(), chgptscnt(), crhold(), cv_init(), finit(), knlist_init_mtx(), lim_cur(), malloc(), pts_class, pts_softc::pts_cred, pts_softc::pts_inpoll, pts_softc::pts_inwait, pts_softc::pts_outpoll, pts_softc::pts_outwait, pts_pool, pts_softc::pts_unit, ptsdev_ops, and tty_alloc().

Referenced by sys_posix_openpt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pts_alloc_external()

int pts_alloc_external ( int  fflags,
struct thread *  td,
struct file *  fp,
struct cdev *  dev,
const char *  name 
)

◆ pts_init()

static void pts_init ( void *  unused)
static

Definition at line 870 of file tty_pts.c.

References new_unrhdr(), and pts_pool.

Here is the call graph for this function:

◆ pts_kqops_read_detach()

static void pts_kqops_read_detach ( struct knote kn)
static

Definition at line 448 of file tty_pts.c.

References knlist_remove(), and pts_softc::pts_outpoll.

Here is the call graph for this function:

◆ pts_kqops_read_event()

static int pts_kqops_read_event ( struct knote kn,
long  hint 
)
static

Definition at line 458 of file tty_pts.c.

References PTS_FINISHED, pts_softc::pts_flags, and ttydisc_getc_poll().

Here is the call graph for this function:

◆ pts_kqops_write_detach()

static void pts_kqops_write_detach ( struct knote kn)
static

Definition at line 474 of file tty_pts.c.

References knlist_remove(), and pts_softc::pts_inpoll.

Here is the call graph for this function:

◆ pts_kqops_write_event()

static int pts_kqops_write_event ( struct knote kn,
long  hint 
)
static

Definition at line 484 of file tty_pts.c.

References PTS_FINISHED, pts_softc::pts_flags, and ttydisc_rint_poll().

Here is the call graph for this function:

◆ ptsdev_close()

static int ptsdev_close ( struct file *  fp,
struct thread *  td 
)
static

Definition at line 574 of file tty_pts.c.

References tty_rel_gone(), and vnops.

Here is the call graph for this function:

◆ ptsdev_fill_kinfo()

static int ptsdev_fill_kinfo ( struct file *  fp,
struct kinfo_file *  kif,
struct filedesc *  fdp 
)
static

Definition at line 595 of file tty_pts.c.

References tty_udev().

Here is the call graph for this function:

◆ ptsdev_ioctl()

static int ptsdev_ioctl ( struct file *  fp,
u_long  cmd,
void *  data,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 261 of file tty_pts.c.

References data, PTS_FINISHED, pts_softc::pts_flags, PTS_PKT, pts_softc::pts_unit, tty_ioctl(), tty_signal_pgrp(), and ttydisc_getc_poll().

Here is the call graph for this function:

◆ ptsdev_kqfilter()

static int ptsdev_kqfilter ( struct file *  fp,
struct knote kn 
)
static

Definition at line 511 of file tty_pts.c.

References knlist_add(), pts_softc::pts_inpoll, pts_kqops_read, pts_kqops_write, and pts_softc::pts_outpoll.

Here is the call graph for this function:

◆ ptsdev_poll()

static int ptsdev_poll ( struct file *  fp,
int  events,
struct ucred *  active_cred,
struct thread *  td 
)
static

◆ ptsdev_read()

static int ptsdev_read ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 114 of file tty_pts.c.

References PTS_FINISHED, pts_softc::pts_flags, pts_softc::pts_outwait, PTS_PKT, pts_softc::pts_pkt, ttydisc_getc_poll(), ttydisc_getc_uio(), and ureadc().

Here is the call graph for this function:

◆ ptsdev_stat()

static int ptsdev_stat ( struct file *  fp,
struct stat *  sb,
struct ucred *  active_cred 
)
static

Definition at line 538 of file tty_pts.c.

References pts_softc::pts_cdev, and tty_udev().

Here is the call graph for this function:

◆ ptsdev_write()

static int ptsdev_write ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 188 of file tty_pts.c.

References PTS_FINISHED, pts_softc::pts_flags, pts_softc::pts_inwait, ttydisc_rint_done(), ttydisc_rint_simple(), and uiomove().

Here is the call graph for this function:

◆ ptsdrv_close()

static void ptsdrv_close ( struct tty *  tp)
static

Definition at line 659 of file tty_pts.c.

References PTS_FINISHED, pts_softc::pts_flags, ptsdrv_inwakeup(), and ptsdrv_outwakeup().

Here is the call graph for this function:

◆ ptsdrv_free()

static void ptsdrv_free ( void *  softc)
static

◆ ptsdrv_inwakeup()

static void ptsdrv_inwakeup ( struct tty *  tp)
static

Definition at line 639 of file tty_pts.c.

References pts_softc::pts_inpoll, pts_softc::pts_inwait, and selwakeup().

Referenced by ptsdrv_close().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ptsdrv_open()

static int ptsdrv_open ( struct tty *  tp)
static

Definition at line 649 of file tty_pts.c.

References pts_softc::pts_flags.

◆ ptsdrv_outwakeup()

static void ptsdrv_outwakeup ( struct tty *  tp)
static

Definition at line 629 of file tty_pts.c.

References pts_softc::pts_outpoll, pts_softc::pts_outwait, and selwakeup().

Referenced by ptsdrv_close(), and ptsdrv_pktnotify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ptsdrv_pktnotify()

static void ptsdrv_pktnotify ( struct tty *  tp,
char  event 
)
static

Definition at line 670 of file tty_pts.c.

References pts_softc::pts_pkt, and ptsdrv_outwakeup().

Here is the call graph for this function:

◆ sys_posix_openpt()

int sys_posix_openpt ( struct thread *  td,
struct posix_openpt_args *  uap 
)

Definition at line 838 of file tty_pts.c.

References fd, fdclose(), and pts_alloc().

Here is the call graph for this function:

◆ SYSINIT()

SYSINIT ( pts  ,
SI_SUB_DRIVERS  ,
SI_ORDER_MIDDLE  ,
pts_init  ,
NULL   
)

Variable Documentation

◆ pts_class

struct ttydevsw pts_class
static
Initial value:
= {
.tsw_flags = TF_NOPREFIX,
.tsw_outwakeup = ptsdrv_outwakeup,
.tsw_inwakeup = ptsdrv_inwakeup,
.tsw_open = ptsdrv_open,
.tsw_close = ptsdrv_close,
.tsw_pktnotify = ptsdrv_pktnotify,
.tsw_free = ptsdrv_free,
}
static void ptsdrv_outwakeup(struct tty *tp)
Definition: tty_pts.c:629
static void ptsdrv_pktnotify(struct tty *tp, char event)
Definition: tty_pts.c:670
static int ptsdrv_open(struct tty *tp)
Definition: tty_pts.c:649
static void ptsdrv_close(struct tty *tp)
Definition: tty_pts.c:659
static void ptsdrv_free(void *softc)
Definition: tty_pts.c:698
static void ptsdrv_inwakeup(struct tty *tp)
Definition: tty_pts.c:639

Definition at line 724 of file tty_pts.c.

Referenced by pts_alloc(), and pts_alloc_external().

◆ pts_kqops_read

struct filterops pts_kqops_read
static
Initial value:
= {
.f_isfd = 1,
.f_detach = pts_kqops_read_detach,
}
static int pts_kqops_read_event(struct knote *kn, long hint)
Definition: tty_pts.c:458
static void pts_kqops_read_detach(struct knote *kn)
Definition: tty_pts.c:448

Definition at line 499 of file tty_pts.c.

Referenced by ptsdev_kqfilter().

◆ pts_kqops_write

struct filterops pts_kqops_write
static
Initial value:
= {
.f_isfd = 1,
}
static void pts_kqops_write_detach(struct knote *kn)
Definition: tty_pts.c:474
static int pts_kqops_write_event(struct knote *kn, long hint)
Definition: tty_pts.c:484

Definition at line 504 of file tty_pts.c.

Referenced by ptsdev_kqfilter().

◆ pts_pool

struct unrhdr* pts_pool
static

Definition at line 79 of file tty_pts.c.

Referenced by pts_alloc(), pts_init(), and ptsdrv_free().

◆ ptsdev_ops

struct fileops ptsdev_ops
static
Initial value:
= {
.fo_read = ptsdev_read,
.fo_write = ptsdev_write,
.fo_truncate = invfo_truncate,
.fo_ioctl = ptsdev_ioctl,
.fo_poll = ptsdev_poll,
.fo_kqfilter = ptsdev_kqfilter,
.fo_stat = ptsdev_stat,
.fo_close = ptsdev_close,
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
.fo_sendfile = invfo_sendfile,
.fo_fill_kinfo = ptsdev_fill_kinfo,
.fo_flags = DFLAG_PASSABLE,
}
int invfo_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
int invfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
int invfo_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags, struct thread *td)
int invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
static int ptsdev_close(struct file *fp, struct thread *td)
Definition: tty_pts.c:574
static int ptsdev_read(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
Definition: tty_pts.c:114
static int ptsdev_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred, struct thread *td)
Definition: tty_pts.c:261
static int ptsdev_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
Definition: tty_pts.c:595
static int ptsdev_poll(struct file *fp, int events, struct ucred *active_cred, struct thread *td)
Definition: tty_pts.c:393
static int ptsdev_kqfilter(struct file *fp, struct knote *kn)
Definition: tty_pts.c:511
static int ptsdev_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
Definition: tty_pts.c:188
static int ptsdev_stat(struct file *fp, struct stat *sb, struct ucred *active_cred)
Definition: tty_pts.c:538

Definition at line 608 of file tty_pts.c.

Referenced by pts_alloc(), and pts_alloc_external().