OPERATING SYSTEMS 12 - FILES PIETER HARTEL 1. Files  Properties  Long term existence of data  Sharable between processes  Access control  Operations.

Slides:



Advertisements
Similar presentations
Concepts about the file system 2. The disk structure 3. Files in disk – The ext2 FS 4. The Virtual File System (c) 2013, Prof. Jordi Garcia.
Advertisements

4.1 Operating Systems Lecture 11 UNIX Pipes Read Handout "An Introduction to Concurrency..."
OPERATING SYSTEMS 8 – VIRTUAL MEMORY PIETER HARTEL 1.
Rings This chapter demonstrates how processes can be formed into a ring using pipes for communication purposes.
Operating Systems File Systems (Select parts of Ch 6)
Friday, June 09, 2006 “I think there is a world market for maybe five computers”. - Thomas Watson, Chairman of IBM, 1943.
File Systems CSE 121 Spring 2003 Keith Marzullo. CSE 121 Spring 2003Review of File Systems2 References In order of relevance... 1)Maurice J. Bach, The.
Guide To UNIX Using Linux Third Edition
Today’s topic Inter-process communication with pipes.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Guide To UNIX Using Linux Fourth Edition
1 UNIX Systems Programming Interprocess communication.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 39 Virtsualization of Storage: File and Directory Chien-Chung Shen CIS, UD
OPERATING SYSTEMS 9 – SCHEDULING PIETER HARTEL 1.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Input and Output Topics I/O hardware Unix file abstraction Robust I/O File sharing io.ppt CS 105 “Tour of the Black Holes of Computing”
Slide 1 Interprocess communication. Slide 2 1. Pipes  A form of interprocess communication Between processes that have a common ancestor  Typical use:
1 System-Level I/O Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Chapter 5 Files and Directories Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
1 UNIX System Programming v Objectives –look at how to program with directories –briefly describe the UNIX file system Directories and File System.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
1 Carnegie Mellon Recitation : Introduction to Computer Systems Recitation 15: December 3, 2012 Daniel Sedra Section C.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
4061 Session 12 (2/22). Today Files and Directories.
Adv. UNIX: dirs/181 Advanced UNIX v Objectives –look at how to program with directories –briefly describe the UNIX file system Special.
Directory structure. Slide 2 Directory Structure  A directory ‘file’ is a sequence of lines; each line holds an i-node number and a file name.  The.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Page 111/15/2015 CSE 30341: Operating Systems Principles Chapter 11: File System Implementation  Overview  Allocation methods: Contiguous, Linked, Indexed,
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Navigating Directories
Today’s topic Access and manipulate meta data for files –File type, ownership, access permissions, access time, etc How to determine if a file is not there?
OPERATING SYSTEMS 1 - HARDWARE PIETER HARTEL 1. Hardware 2.
The UNIX File System (1) Some important directories found in most UNIX systems.
Linux File system Implementations
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Linux Filesystem WeeSan Lee. Roadmap Disk Partitions The Filesystem Filesystem Mouting & Umounting File Tree File Type File Permission.
Pipes Pipes are an inter-process communication mechanism that allow two or more processes to send information to each other.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Interface.
NCHU System & Network Lab Lab 14 File and Directory.
THE FILE SYSTEM Files long-term storage RAM short-term storage Programs, data, and text are all stored in files, which is stored on.
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
CSE333 SECTION 3. Important Dates Jan 27 th – Homework 1 Due Feb 6 th – Midterm.
CS 241 Section Week #8 (10/29/09). Outline MP5 Overview Files & I/O UNIX File Systems inodes Directories Links.
OPERATING SYSTEMS 3 - PROCESSES PIETER HARTEL 1. Principle of concurrency - giving a process the illusion that it owns the whole machine  A process has:
1 PART II System Programming. 2 Chapter 10 The File and I/O System.
Dup, dup2 An existing file descriptor ( filedes ) is duplicated The new file descriptor returned by dup is guaranteed to be the lowest numered available.
CSC 271 – Software I: Utilities and Internals An Introduction to File I/O in Linux Credited to Dr. Robert Siegfried and Beginning Linux Programming by.
Chapter 39 File and Directory Chien-Chung Shen CIS/UD
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Pipes and Fifos.
Getting Started with Linux
Chapter 6 File Systems CSNB113 SYSTEM ADMINISTRATION
Command Line Arguments
Linux Kernel Driver.
Pipe.
Genesis: From Raw Hardware to Processes
Outline Allocation Free space management Memory mapped files
INTRODUCTION TO UNIX: The File System
Persistence: File System API
IPC Prof. Ikjun Yeom TA – Hoyoun
Chap 4: Distributed File Systems
dup, dup2 An existing file descriptor (filedes) is duplicated
프로그래밍2 및 실습 Sort Code 전명중.
Chapter 11: File-System Interface CSS503 Systems Programming
System Programming: Process Management
Presentation transcript:

OPERATING SYSTEMS 12 - FILES PIETER HARTEL 1

Files  Properties  Long term existence of data  Sharable between processes  Access control  Operations  Create/Delete  Open/Close  Read/Write/Seek  Structure  Bytes/Records 2

Directories  Path name  Current directory  Parent directory  Root directory  ls -ld... / 3

Hard and symbolic links  rm a b c  echo "Hello World" >a  ln a b  ls -li a b  rm a  cat b  ln b a  ls -li a b 4  ln -s a c  cat c  rm a b  ls -li c  cat c  echo "Hello World" >a  ls -li a c  cat c Inodes? Ref count? Inodes? Ref count?

int main(int argc, char* argv[]) { int i, n = (argc==1?1:atoi(argv[1])); char top[M], cur[M], tmp[M]; getcwd(top,M); printf("top=%s\n",top); strcpy(cur, "."); for(i=0; i<n; i++) { strcpy(tmp, cur); sprintf(cur, "%s/Foo", tmp); mkdir(cur, 0755); sprintf(tmp, "%s/Foo_%d", top, i); symlink(cur, tmp); } return 0; } Making and removing a directory  gcc Mkdir.c ./a.out 4  ls –lRi Foo*  strace./a.out 4 5 Time (s) Depth

Linux ext2 partition  Per device:  Boot block  Super block  Inode table  Data blocks  stat -f /  stat -f $HOME  ls -ldi...../..../../.. / /.. 6

int main(int argc, char * argv[]) { DIR *dirp = opendir(argv[1]) ; for(;;) { struct dirent *dp = readdir(dirp); if( dp != NULL ) { char t = … ; printf("%d %c %s\n", dp->d_ino, t, dp->d_name); } else { break ; } closedir(dirp); return 0; } Reading a directory  gcc Readdir.c ./a.out / ./a.out.  Why is the root inode #2 7

int main(int argc, char **argv) { int r, fd[2]; pipe(fd); pid_t pid=fork(); if(pid== 0) { close(fd[1]); read(fd[0], &r, sizeof (int)); printf("child %d\n", r); close(fd[0]); } else { close(fd[0]); srand(time(NULL)); r = rand(); printf("parent %d\n", r); write(fd[1], &r, sizeof (int)); close(fd[1]); waitpid(pid,0,0); } return 0; } Unnamed pipe  Output?  gcc Pipe.c ./a.out  Try this a few times… 8

int main(int argc, char **argv) { int r; mkfifo(argv[1], 0666) ; pid_t pid=fork(); if(pid== 0) { int fd = open(argv[1], O_RDONLY); read(fd, &r, sizeof (int)); printf("child %d\n", r); close(fd); } else { int fd = open(argv[1], O_WRONLY, 0666); srand(time(NULL)); r = rand(); printf("parent %d\n", r); write(fd, &r, sizeof (int)); close(fd); waitpid(pid,0,0); } return 0; } Named pipe  Output?  gcc Fifo.c ./a.out foo  ls –l foo 9

char *lookup(char *pth, char *mnt) { struct mntent m; struct stat s; stat(pth, &s); dev_t d = s.st_dev; ino_t i = s.st_ino; FILE *f = setmntent("/proc/mounts", "r"); while (getmntent_r(f, &m, mnt, M)) { if (stat(m.mnt_dir, &s) != 0) { continue; } if (s.st_dev == d && s.st_ino == i) { return mnt ; } endmntent(f); return NULL; } Mount points  more /proc/mounts  gcc Mount.c ./a.out $HOME  lookup(“/home/lecturer”,…)  lookup(“/home”,…)  lookup(“/”,…) 10

Summary  File management maps logical files onto disk blocks  Directory structure allows efficient lookup of files  Disk blocks are used for paging and swapping too  Everything is cached in memory 11