Poster of Linux kernelThe best gift for a Linux geek
 Linux kernel map 
⇦ prev ⇱ home next ⇨

18.7. The tty_operations Structure in Detail

The tty_operations structure contains all of the function callbacks that can be set by a tty driver and called by the tty core. Currently, all of the function pointers contained in this structure are also in the tty_driver structure, but that will be replaced soon with only an instance of this structure.

int (*open)(struct tty_struct * tty, struct file * filp);

The open function.

void (*close)(struct tty_struct * tty, struct file * filp);

The close function.

int (*write)(struct tty_struct * tty, const unsigned char *buf, int count);

The write function.

void (*put_char)(struct tty_struct *tty, unsigned char ch);

The single-character write function. This function is called by the tty core when a single character is to be written to the device. If a tty driver does not define this function, the write function is called instead when the tty core wants to send a single character.

void (*flush_chars)(struct tty_struct *tty);

void (*wait_until_sent)(struct tty_struct *tty, int timeout);

The function that flushes data to the hardware.

int (*write_room)(struct tty_struct *tty);

The function that indicates how much of the buffer is free.

int (*chars_in_buffer)(struct tty_struct *tty);

The function that indicates how much of the buffer is full of data.

int (*ioctl)(struct tty_struct *tty, struct file * file, unsigned int cmd,

unsigned long arg);

The ioctl function. This function is called by the tty core when ioctl(2) is called on the device node.

void (*set_termios)(struct tty_struct *tty, struct termios * old);

The set_termios function. This function is called by the tty core when the device's termios settings have been changed.

void (*throttle)(struct tty_struct * tty);

void (*unthrottle)(struct tty_struct * tty);

void (*stop)(struct tty_struct *tty);

void (*start)(struct tty_struct *tty);

Data-throttling functions. These functions are used to help control overruns of the tty core's input buffers. The throttle function is called when the tty core's input buffers are getting full. The tty driver should try to signal to the device that no more characters should be sent to it. The unthrottle function is called when the tty core's input buffers have been emptied out, and it can now accept more data. The tty driver should then signal to the device that data can be received. The stop and start functions are much like the throttle and unthrottle functions, but they signify that the tty driver should stop sending data to the device and then later resume sending data.

void (*hangup)(struct tty_struct *tty);

The hangup function. This function is called when the tty driver should hang up the tty device. Any special hardware manipulation needed to do this should occur at this time.

void (*break_ctl)(struct tty_struct *tty, int state);

The line break control function. This function is called when the tty driver is to turn on or off the line BREAK status on the RS-232 port. If state is set to -1, the BREAK status should be turned on. If state is set to 0, the BREAK status should be turned off. If this function is implemented by the tty driver, the tty core will handle the TCSBRK, TCSBRKP, TIOCSBRK, and TIOCCBRK ioctls. Otherwise, these ioctls are sent to the driver to the ioctl function.

void (*flush_buffer)(struct tty_struct *tty);

Flush buffer and lose any remaining data.

void (*set_ldisc)(struct tty_struct *tty);

The set line discipline function. This function is called when the tty core has changed the line discipline of the tty driver. This function is generally not used and should not be defined by a driver.

void (*send_xchar)(struct tty_struct *tty, char ch);

Send X-type char function. This function is used to send a high-priority XON or XOFF character to the tty device. The character to be sent is specified in the ch variable.

int (*read_proc)(char *page, char **start, off_t off, int count, int *eof,

void *data);

int (*write_proc)(struct file *file, const char *buffer, unsigned long count,

void *data);

/proc read and write functions.

int (*tiocmget)(struct tty_struct *tty, struct file *file);

Gets the current line settings of the specific tty device. If retrieved successfully from the tty device, the value should be returned to the caller.

int (*tiocmset)(struct tty_struct *tty, struct file *file, unsigned int set,

unsigned int clear);

Sets the current line settings of the specific tty device. set and clear contain the different line settings that should either be set or cleared.

    ⇦ prev ⇱ home next ⇨
    Poster of Linux kernelThe best gift for a Linux geek