程序代写代做代考 file system CSci 4061 Introduction to Operating Systems

CSci 4061 Introduction to Operating Systems
Input/Output: Low-level cont’d Getting real low Chapter 4, 6.5

Unix Devices
• All devices integrated into the Unix filesystem
• Block devices
• I/O is fixed–size blocks: disk;
• Character devices
• I/O is byte streams: terminal, modems, …
• Pseudo devices
• Not really a physical device
• Ex: Remote terminal: ssh/telnet window

Device Access and Control
• Neat aspect of Unix Devices
• All I/O sources/sinks of data are treated as files! • All devices mapped to fd’s
• Can be named like files “/dev/…”
• read, write, …

Devices and special files • The terminal is a special file
• Terminal fd needed in order to control it: “/dev/tty” • Details (Chap 6.5)
• Pseudo-terminal ssh/telnet: “/dev/pts/#” [run stty –a ; tty]

Terminal Control
• Terminal control is important to many systems programs and applications
• Suppress character echoing from the keyboard => e.g. passwords
• Disable ^C (interrupt) => e.g unsafe to stop a program that is writing files
• Process input immediately => e.g. auto command completion

Terminal Control • Other options:
• Change characters for: interrupt, erase, eof, eol characters
• Change screen dimensions
• Address special locations on the screen • Fonts

Controlling Terminal
#include
char termbuf [L_ctermid];
ctermid (termbuf);
// controlling terminal name, “/dev/tty”
fd = open (termbuf, O_RDONLY);

Controlling Terminal (cont’d)
#include int tcgetattr
(int fildes,
struct termios *termios_p);
int tcsetattr
(int fildes,
int optional_actions,
const struct termios *termios_p);
Optional_actions: when changes take affect,
TCSAFLUSH
Paradigm: get, modify, set

Controlling Terminal (cont’d)
struct termios:
tcflag_t c_iflag; // input (e.g. CR)
tcflag_t c_oflag; // output (newline=CR) tcflag_t c_cflag; // control h/w
tcflag_t c_lflag; // local/editing (e.g. ECHO) cc_t c_cc [NCCS]; // control chars (e.g. intr is ^g)
Tables 6.1, 6.2

Examples
• Disable echoing
[run secho]
• Disable interrupts [run noescape]

Canonical Model
• When does your process obtain input from stdin?
read (0, buf, BUF_SIZE);
• Canonical: line-oriented input
• erase, backspace have meaning
• Non-canonical:
• MIN characters to wait for read to return • TIME how long to wait for something
• What is a terminal by default? [run canonical/noncanonical]

Next Time • File Systems
• Read Chapter 5 R&R
• Have a great weekend!