Lecture9 - CSCE 313 Introduction to Computer Systems...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSCE 313 Introduction to Computer Systems Instructor: Dr. Ronnie Ward Based on material from Dr. Guofei Gu UNIX I/O • Files and File Representation • Basic operations: Reading / Writing • Caching: File Open / Close • Multiplexing: Select / Poll • File Descriptors • Reading: R&R, Ch 4 Note : Some material in this set of slides comes from Solomon&Russinovich, “Inside Windows 2000,” Microsoft Programming Series. What is a File? • A file is a collection of data elements, grouped together for purpose of access control, retrieval, and modification • Often, files are mapped onto physical storage devices, usually non- volatile. • Some modern systems define a file simply as a stream , or sequence of data units. • ==> Files don’t need to be persistent. (We can call any stream of data units a file!) File Descriptors: Uniform Device Interface CPU CPU modem network mouse printer keyboard mass storage graphics memory memory Device independent I/O model File Operations: Read/Write: read #include <unistd.h> ssize_t read (int fildes, void & buf, size_t n_byte); ECONNRESET : read attempted on a socket and connection was forcibly closed by peer EAGAIN : O_NONBLOCK is set for file descriptor and thread would be delayed EBADF : fildes is not a valid file descriptor open for reading EINTR : read was terminated due to receipt of a signal and no data was transferred EIO : <paraphrased: process has problems reading from controlling terminal> ENOTCONN : read socket is not connected EOVERFLOW : <for regular files> starting position exceeds offset maximum ETIMEDOUT : read on socket, and transmission timeout occurred EWOULDBLOCK : file descriptor is for socket marked O_NONBLOCK and no data is waiting to be received. read Example #include <errno.h> #include <unistd.h> ssize_t r_read (int fd, void * buf, size_t size) { ssize_t ret_val; while (ret_val = read (fd, buf, size) == -1 && errno == EINTR); return ret_val; } r_read similar to read except that it restarts if interrupted and reads the full amount what does a ret_val of 0 indicate? File Operations: Read/Write #include <unistd.h> ssize_t write (int fildes, const void & buf, size_t n_byte); ECONNRESET : write attempted on a socket and connection was forcibly closed by peer EAGAIN : O_NONBLOCK is set for file descriptor and thread would be delayed EBADF : fildes is not a valid file descriptor open for writing EINTR : write was terminated due to receipt of a signal and no data was transferred EIO : <paraphrased: process has problems writing to controlling terminal> ENOSPC : no free space remaining on device containing the file EPIPE : attempt to write to a closed pipe or closed connection EWOULDBLOCK : file descriptor is for socket marked O_NONBLOCK and write would block write...
View Full Document

This note was uploaded on 02/14/2012 for the course CSCE 313 taught by Professor Gu during the Spring '11 term at Texas A&M.

Page1 / 25

Lecture9 - CSCE 313 Introduction to Computer Systems...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online