Exercise ● Exercise 4.15: Write a version of mkdir which supports the - p option. Due by class 2/23....

Slides:



Advertisements
Similar presentations
Linux Serial Programming for POSIX Operating Systems
Advertisements

?  Able to explain the 6 key functions of system software  Able to explain each using a suitable example  Identify three different system software.
I/O means Input and Output. One way: use standard input and standard output. To read in data, use scanf() (or a few other functions) To write out data,
CSCI 1730 April 1 st, Materials Class notes slides & some “plain old” html & source code examples linked from course calendar board notes & diagrams.
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
Terminal Control operating systems. Terminal Control may seem like an arcane subject, but … It illustrates the relationship between devices and files.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
Terminal Control Many special files represent devices that are platform dependent, making standardization difficult POSIX standards committee decided to.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
1 Advanced programming in UNIX 1 File I/O Hua LiSystems ProgrammingCS2690File I/O.
1 Device Management The von Neumann Architecture System Architecture Device Management Polling Interrupts DMA operating systems.
Practical Session No. 10 Input &Output (I/O). I/O Devices Input/output (I/O) devices provide the means to interact with the “outside world”. An I/O device.
I/O Systems ◦ Operating Systems ◦ CS550. Note:  Based on Operating Systems Concepts by Silberschatz, Galvin, and Gagne  Strongly recommended to read.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students C File Input and Output Checking input for errors.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 5. Connection Controls. Device == File ? Filenames Properties permission bits system call – open, read, write, lseek, close, stat.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
Chapter 4. INTERNAL REPRESENTATION OF FILES
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
File Handling In C By - AJAY SHARMA. We will learn about- FFile/Stream TText vs Binary Files FFILE Structure DDisk I/O function OOperations.
The tty Interface An introduction to “systems programming” in the Linux environment.
UNIX Files File organization and a few primitives.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Exceptional Control Flow
OPERATING SYSTEM CONCEPT AND PRACTISE
Serial mode of data transfer
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
A bit of C programming Lecture 3 Uli Raich.
Microprocessor Systems Design I
Chapter 7 Text Input/Output Objectives
Input/Output.
Serial I/O and Data Communication.
UNIX System Overview.
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Chapter 8 I/O.
Chapter 2 part #3 C++ Input / Output
The slides must be understood in Lecture 5
An overview of the kernel structure
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
MARIE: An Introduction to a Simple Computer
CS703 - Advanced Operating Systems
Advanced UNIX programming
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
FILE HANDLING IN C.
Chapter 8 I/O.
File Input and Output.
Advanced UNIX progamming
Programming in C Input / Output.
Chapter 8 I/O.
FILE I/O File Descriptors I/O Efficiency File Sharing
Chapter 2 part #3 C++ Input / Output
EPSII 59:006 Spring 2004.
Internal Representation of Files
Chapter 12: File-System Implementation CSS503 Systems Programming
Presentation transcript:

Exercise ● Exercise 4.15: Write a version of mkdir which supports the - p option. Due by class 2/23....

Unions ● mytime.simpleDate is an integer of 4 bytes. ● mytime.preciseDate is a double. ● sizeof(mytime)=8. ● Tags can be used to indicate which field is active. ● struct conditions { float temp; union feels_like { float wind_chill; float heat_index; } } today;

Unions ● mytime.simpleDate is an integer of 4 bytes. ● mytime.preciseDate is a double. ● sizeof(mytime)=8. ● Tags can be used to indicate which field is active. ● struct conditions { float temp; union feels_like { float wind_chill; float heat_index; } } today;

Devices and Files ● Device I/O is like File I/O ● Every device (terminal, printer, mouse, etc) is attached to the file system by a file name. ● Devices are usually stored in /dev ● You communicate with devices with read, write, open, close, lseek ● example: who > /dev/pts/4 ● cp /etc/passwd /dev/pts/4

Devices and Files ● There are some special files: – /dev/null – a data sink – /dev/zeros – all the zeros you could ever want – /dev/mem – kernel interface to memory ● Open, read, write,close do what you expect. lseek is not defined for all devices. ● File permission, mod time, owner, types are stored in inode. ● Use stat to examine ● stty

Devices and Files ● Connections to device are not hollow tubes; they sometimes contain a complex sequences of steps ● A fd has a buffering mechanism ● A terminal has baud rates, parity, stop bits, echo-mode, buffering, cr translation

Devices and Files ● The features of a device connections can be controlled by fcntl ● #include int v; v=fcntl(fd,F_GETFL) //get flags v |= O_SYNC //set sync bit fcntl(fd,F_SETFL,v) //set flags now write()s to disk will be synced to the disk

Devices and Files ● auto-append mode is another fd attribute ● Consider logfiles like wtmp

Devices and Files ● Solution: set O_APPEND #include int v; v=fcntl(fd,F_GETFL) //get flags v |= O_APPEND//set sync bit fcntl(fd,F_SETFL,v) //set flags ● This makes lseek-write ATOMIC ● See man 2 open

Terminal ● Terminals have – buffering – autoappend ● They behave much differently than files – all connects to a tty (pty) have attributes of regular files – all connections to ttys have additional attributes appropriate for human interfaces

Terminals naïve view

Terminals less naïve view

Terminals ● Consider stty. ● To write user programs like an editor we have to be able to read and change the properties of a terminal. ● tcgetattr and tcsetattr ● struc termios ● termios_p : pointer to struct termios

Terminals ● #include struct termios settings; tcgettattr(fd,&settings); //test or clear bits tcsetattr(fd, TCSANOW, &settings);

Terminals TCSANOW the change occurs immediately. TCSADRAIN the change occurs after all output written to fd has been transmitted. This function should be used when changing param- eters that affect output. TCSAFLUSH the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made.

Terminals

#include /** **showtty **displays some of current tty settings**/ main() {structtermios ttyinfo;/* this struct holds tty info */ if ( tcgetattr( 0, &ttyinfo ) == -1 ){ /* get info */ perror( "cannot get params about stdin"); exit(1);}/* show info */ showbaud ( cfgetospeed( &ttyinfo ) );/* get + show baud rate*/ printf("The erase character is ascii %d, Ctrl-%c\n", ttyinfo.c_cc[VERASE], ttyinfo.c_cc[VERASE]-1+'A'); printf("The line kill character is ascii %d, Ctrl-%c\n", ttyinfo.c_cc[VKILL], ttyinfo.c_cc[VKILL]-1+'A'); show_some_flags( &ttyinfo );/* show misc. flags*/ }

Terminals showbaud( thespeed ) /*prints the speed in english*/ { printf("the baud rate is "); switch ( thespeed ){ case B300:printf("300\n");break; case B600:printf("600\n"); break; case B1200:printf("1200\n"); break; case B1800:printf("1800\n"); break; case B2400:printf("2400\n"); break; case B4800:printf("4800\n"); break; case B9600:printf("9600\n"); break; default:printf("Fast\n");break; }

Terminals struct flaginfo { intfl_value; char*fl_name; }; struct flaginfo input_flags[] = { IGNBRK,"Ignore the break condition", BRKINT,"Signal interrupt on break", IGNPAR,"Ignore chars with parity errors", PARMRK,"Mark parity errors", INPCK,"Enable input parity check", ISTRIP,"Strip character", INLCR,"Map NL to CR on input", IGNCR,"Ignore CR", ICRNL,"Map CR to NL on input", IXON,"Enable start/stop output control", /* _IXANY,"enable any char to restart output",*/ IXOFF,"Enable start/stop input control", 0,NULL };

Terminals s truct flaginfo local_flags[] = { ISIG,"Enable signals", ICANON,"Canonical input (erase and kill)", /* _XCASE,"Canonical upper/lower appearance", */ ECHO,"Enable echo", ECHOE,"Echo ERASE as BS-SPACE-BS", ECHOK,"Echo KILL by starting new line", 0,NULL }; show_some_flags( struct termios *ttyp ) /* *show the values of two of the flag sets_: c_iflag and c_lflag *adding c_oflag and c_cflag is pretty routine - just add new *tables above and a bit more code below. */ {show_flagset( ttyp->c_iflag, input_flags ); show_flagset( ttyp->c_lflag, local_flags );}

Terminals show_flagset( int thevalue, struct flaginfo thebitnames[] ) /* * check each bit pattern and display descriptive title */ { inti; for ( i=0; thebitnames[i].fl_value ; i++ ) { printf( " %s is ", thebitnames[i].fl_name); if ( thevalue & thebitnames[i].fl_value ) printf("ON\n"); else printf("OFF\n"); }