UNIX Files File organization and a few primitives.

Slides:



Advertisements
Similar presentations
CS 241 Section Week #5 2/23/12. 2 Topics This Section MP4 overview Function Pointers Pthreads File I/O.
Advertisements

Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
04/14/2008CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Lecture 17 FS APIs and vsfs. File and File Name What is a File? Array of bytes. Ranges of bytes can be read/written. File system consists of many files,
1 Course Outline Processes & Threads CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Networks, Protection and Security.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
UNIX Processes 1: Introduction.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
System Calls 1.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Introduction to Processes CS Intoduction to Operating Systems.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-2: I/O Management (Review) Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
I/O Systems I/O Hardware Application I/O Interface
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Linux File system Implementations
XE33OSA Chapter 13: I/O Systems. 13.2XE33OSA Silberschatz, Galvin and Gagne ©2005 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel.
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Operating Systems, Spring 2003 Local File Systems in UNIX Ittai Abraham Zinovi Rabinovich (recitation)
CSE333 SECTION 3. Important Dates Jan 27 th – Homework 1 Due Feb 6 th – Midterm.
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.
File Systems - Part I CS Introduction to Operating Systems.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
I/O Software CS 537 – Introduction to Operating Systems.
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.
CS 241 Section Week #5 9/22/11. 2 Topics This Section File I/O Advanced C.
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.
File System Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki CS 314.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Chapter 13: I/O Systems.
Introduction to Kernel
Module 12: I/O Systems I/O hardware Application I/O Interface
Lecture 31: Introduction to File System
An overview of the kernel structure
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
CSE 333 – Section 3 POSIX I/O Functions.
CSE 333 – Section 3 POSIX I/O Functions.
Advanced UNIX progamming
CSE 333 – Section 3 POSIX I/O Functions.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Low-Level I/O – the POSIX Layer CSE 333 Winter 2019
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

UNIX Files File organization and a few primitives

The UNIX file system! Each UNIX file has a description that is stored in a structure called inode. An inode includes: file size location owner (uid) permissions access times etc.

Directories A UNIX directory is a file containing a correspondence between inodes and filenames. When referencing a file, the Operating System (OS) traverses the File System tree to find the inode/name in the appropriate directory. Once the OS has determined the inode number it can access the inode to get information about the file.

Links A link is an association between a filename and an inode. We distinguish 2 types of links: hard links soft (or symbolic) links Directory entries are hard links as they directly link an inode to a filename. Symbolic links use the file (contents) as a pointer to another filename.

More on links each inode may be pointed to by a number of directory entries (hard links) each inode keeps a counter, indicating how many hard links exist to that inode. When a hard link is removed via the rm or unlink command, the OS removes the corresponding link but does not free the inode and corresponding data blocks until the link count is 0

Different types of files UNIX deals with two different classes of files: Special Files Regular Files Regular files are just ordinary data files on disk - something you have used all along when you studied programming! Special files are abstractions of devices. UNIX deals with devices as if they were regular files. The interface between the file system and the device is implemented through a device driver - a program that hides the details of the actual device.

special files UNIX distinguishes two types of special files: Block Special Files represent a device with characteristics similar to a disk. The device driver transfers chunks or blocks of data between the operating system and the device. Character Special Files represent devices with characteristics similar to a keyboard. The device is abstracted by a stream of bytes that can only be accessed in sequential order.

Access Primitives UNIX provides access to files and devices through a (very) small set of basic system calls (primitives) create() open() close() read() write() ioctl()

the open() call #include int open(const char *path, int flags, [mode_t mode]); char *path: is a string that contains the fully qualified filename of the file to be opened. int flags: specifies the method of access i.e. read_only, write_only read_and_write. mode_t mode: optional parameter used to set the access permissions upon file creation.

read() and write() #include ssize_t read(int filedes, void *buffer, size_t n); ssize_t write(int filedes, const void *buffer, size_t n); int filedes: file descriptor that has been obtained though an open() or create() call. void *buffer: pointer to an array that will hold the data that is read or holds the data to be written. size_t n: the number of bytes that are to be read or written from/to the file.

A close() call Although all open files are closed by the OS upon completion of the program, it is good programming style to “ clean up ” after you are done with any system resource. Please make it a habit to close all files that your program has used as soon as you don ’ t need them anymore! #include int close(int filedes); Remember, closing resources timely can improve system performance and prevent deadlocks from happening (more later)

A rudimentary example: #include /* controls file attributes */ #include /* defines symbolic constants */ main() { int fd; /* a file descriptor */ ssize_t nread;/* number of bytes read */ char buf[1024];/* data buffer */ /* open the file “ data ” for reading */ fd = open( “ data ”, O_RDONLY); /* read in the data */ nread = read(fd, buf, 1024); /* close the file */ close(fd); }

C Versions of Read, Write, … C provides its own versions of read, write, open, close, namely fread fwrite fopen fclose fflush --- ??? The C versions are more portable as they are defined in the language itself. The “OS” versions (read, write, …) usually allow for more efficient manipulation of files

Buffered vs unbuffered I/O The system can execute in user mode or kernel mode! Memory is divided into user space and kernel space! What happens when we write to a file?  the write call forces a context switch to the system. What??  the system copies the specified number of bytes from user space into kernel space. (into mbufs)  the system wakes up the device driver to write these mbufs to the physical device (if the file-system is in synchronous mode).  the system selects a new process to run.  finally, control is returned to the process that executed the write call. What are the effects on the performance of your program?

Un-buffered I/O Every read and write is executed by the kernel. Hence, every read and write will cause a context switch in order for the system routines to execute. Why do we suffer performance loss? How can we reduce the loss of performance? ==> We could try to move as much data as possible with each system call. How can we measure the performance?

Buffered I/O explicit versus implicit buffering: explicit - collect as many bytes as you can before writing to file and read more than a single byte at a time. Then, use the basic UNIX I/O primitives  Careful !! Your program my behave differently on different systems.  Here, the programmer is explicitly controlling the buffer-size implicit - use the Stream facility provided by FILE *fd, fopen, fprintf, fflush, fclose,... etc. a FILE structure contains a buffer (in user space) that is usually the size of the disk blocking factor (512 or 1024)

Life Cycle of An I/O Request

Interrupt-Driven I/O Cycle

Intel Pentium Processor Event- Vector Table

Direct Memory Access Used to avoid programmed I/O for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory

Six Step Process to Perform DMA Transfer

Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers Use DMA Balance CPU, memory, bus, and I/O performance for highest throughput