Standard Line Discipline¶
The tty subsystem provides a standard line discipline for processing input and output.
This line discipline is implemented in os/drivers/tty/tty_ldisc_std.c
Implement the standard line discipline for a tty.
General Considerations¶
The line discipline of a tty is the component that is responsible for processing user input and then buffer it until it is read by a user process. Depending on the state of the line discipline, output may be echoed, i.e., printed to the screen. Furthermore, it takes output from a user process, processes it and passes it to the tty driver, e.g., for outputting it to the screen.
Initialization¶
This line discipline is initialized by calling
-
void tty_ldisc_std_init(void)¶
Initialize the standard line discipline.
Registering the Line Discipline to a TTY¶
This line discipline is registered to a tty by calling
Implemented Line Discipline Operations¶
This line discipline implements the following line discipline operations:
Passing Input to the Line Discipline¶
Input can be passed by the receive_char() operation, implemented in
-
static void __tty_ldisc_std_ops_receive_char(tty_t *tty, char c)¶
Receive and handle an input character passed from lower levels.
pass downstream, or
handle, e.g.,
enter
end of transmission (^D)
backspace
end of text (^C)
form feed (^L)
This function uses the following helper:
Opening the Line Discipline¶
The line discipline is opened, i.e., initialized, by calling the open()
operation, implemented in
Reading Input from the Line Discipline¶
Buffered input is read from the line discipline by calling the read()
operation, implemented in
-
static ssize_t __tty_ldisc_std_ops_read(tty_t *tty, file_t *file, char *buffer, size_t buffer_size, size_t *offset)¶
Handle read issued by higher levels, i.e., user processes.
When a user process is attempting to read from a tty, that tty will pass the request on to the line discipline. The line discipline will then copy the content of its input buffer to the
bufferof the reading process.Note
This operation blocks until input becomes available.
- Parameters:
tty – : the tty to read from
file – : the file to rad from
buffer – : the buffer to read the data into
buffer_size – : the size of that buffer
offset – : the offset in the file
Writing Output to the Line Discipline¶
Output is written to the line discipline by calling the write() operation,
implemented in
-
static ssize_t __tty_ldisc_std_ops_write(tty_t *tty, file_t *file, const char *buffer, size_t buffer_size, size_t *offset)¶
Handle write issued by higher levels, i.e., user processes.
When a user process is attempting to write to a tty, that tty will pass the request on the line discipline. The line discipline will then copy the content of the output
bufferto the the lower level console.- Parameters:
tty – : the tty to write to
file – : the file to write to
buffer – : the buffer to write the data from
buffer_size – : the size of that buffer
offset – : the offset in the file
Internal Data¶
The line discipline stores its data in the following data structure which is
then stored in the field tty_t.ldisc_data
-
struct tty_ldisc_std_data_t¶
The standard line discipline’s private data.
Public Members
-
size_t input_pos¶
End of input already received from lower level.
-
size_t edit_pos¶
Position to place new input to, i.e., cursor position.
-
size_t read_pos¶
End of input already read by higher level.
-
char input_buffer[1024]¶
Buffer for input.
-
bool input_available¶
Denote that input has been received which is ready to be read.
-
size_t input_pos¶