{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture9 - ComputerSystems Instructor:Dr.RonnieWard...

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

View Full Document Right Arrow Icon
CSCE 313 Introduction to  Computer Systems Instructor: Dr. Ronnie Ward Based on material from Dr. Guofei Gu
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
What is a File? 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!)
Image of page 3

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

View Full Document Right Arrow Icon
File Descriptors: Uniform Device Interface CPU CPU modem network mouse printer keyboard mass storage graphics memory memory Device independent I/O model
Image of page 4
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.
Image of page 5

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

View Full Document Right Arrow Icon
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?
Image of page 6
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 :
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern