1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.

Slides:



Advertisements
Similar presentations
More on File Management
Advertisements

Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
File Management. Persistent storage Shared device Why Programmers Need Files HTML Editor HTML Editor … … Web Browser Web Browser Structured information.
File System – Unix baed. An entry of Active File table: 1. Access Right: r/w/x 2. Process Count: no. of processes which are now referring to the file.
File System Interface CSCI 444/544 Operating Systems Fall 2008.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
Operating Systems File Systems CNS 3060.
1 UNIX 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX.
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
Operating Systems File Systems (in a Day) Ch
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Operating Systems File Systems (Select parts of Ch 6)
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
CSE 451 Section 4 Project 2 Design Considerations.
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,
7/3/20151 Announcement (No deadline extension for the rest of quarter) Project 2 final deadline is Tuesday midnight May 19 Project 0 resubmission for autograding.
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.
EFS: encrypted File system Project by: Andrew Grossman Gaurav Gupta CMSC 691X-Summer 2002 University of Maryland Baltimore County.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
I/O Systems ◦ Operating Systems ◦ CS550. Note:  Based on Operating Systems Concepts by Silberschatz, Galvin, and Gagne  Strongly recommended to read.
System Calls 1.
Networked File System CS Introduction to Operating Systems.
CSCC69: Operating Systems Assignment 3 Review. Assignment Review Implement the file-related system calls – open, close, dup2 – read, write, lseek – chdir,
ITEC 502 컴퓨터 시스템 및 실습 Chapter 10-1: File Systems Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
SIMULATED UNIX FILE SYSTEM Implementation in C Tarek Youssef Bipanjit Sihra.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Project 2: Initial Implementation Notes Tao Yang.
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
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Slide 13-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter File Management.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Processes and Virtual Memory
Css430 file-system implementation1 CSS430 File-System Implementation Textbook Ch12 These slides were compiled from the OSC textbook slides (Silberschatz,
CSCC69: Operating Systems Tutorial 10. Hints on testing Assignment 3 How to test tlb replacement algorithms? – Write a program that creates an array larger.
Pintos project 3: Virtual Memory Management
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally FILE SYSTEM.
4P13 Week 9 Talking Points
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
File Systems - Part I CS Introduction to Operating Systems.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
I/O Software CS 537 – Introduction to Operating Systems.
MINIX Presented by: Clinton Morse, Joseph Paetz, Theresa Sullivan, and Angela Volk.
COMP 3500 Introduction to Operating Systems Project 4 – Virtual Memory Part 1: Overview Dr. Xiao Qin Auburn University
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 3: Adding System Calls to OS/161 Dr. Xiao Qin Auburn University.
COMP 3500 Introduction to Operating Systems Directory Structures Block Management Dr. Xiao Qin Auburn University
CSE120 Discussion 5 Xinxin Jin. Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level.
Auburn University COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 5: Managing.
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Chapter 12: File System Implementation
Case Study 1: UNIX and LINUX
COMP 3500 Introduction to Operating Systems File Management
Operation System Program 4
Making Virtual Memory Real: The Linux-x86-64 way
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Operating Systems Lecture 3.
CSCI 380: Operating Systems William Killian
Chapter 12: File-System Implementation CSS503 Systems Programming
Presentation transcript:

1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University

Review: How to Test System Calls? Step 1 Create a User Program for the New System Call Step 2 Run the User Program in OS/161 2

Step 1.1 Create a new directory using forktest as a template We place all the test programs in the following directory: ~/cs161/src/testbin Each test program and its associated files (e.g., Makefile) are organized in a dedicated directory. Create a new directory using forktest as a template %cd ~/cs161/src/testbin %cp –r forktest getpidtest 3

Step 1.2 Change source code name %cd getpidtest %mv forktest.c getpidtest.c 4

Step 1.3 Modify getpidtest.c #include int main() { int mypid; mypid = getpid(); reboot(RB_REBOOT); return 0; } 5

Step 1.4 Modify Makefile and depend.mk Modify Makefile and depend.mk by replacing forktest with getpidtest 6

Step 1.5 Compile getpidtest.c Compile getpidtest.c using cs161-gcc. This can be done through running Makefile as below. %make The make utility program compile getpidtest.c and generate an execute file called getpidtest 7

A Sample Problem with Makefile File getpidtest.c doesn’t exist You're in the wrong directory when you run make Check your Makefile getpidtest.o: getpidtest.c getpidtest.h gcc -c getpidtest.c No space, TAB only No comma 8

Step 1.6 Copy the executable file to the root directory Copy the executable file getpidtest into ~/cs161/root/testbin %cp getpidtest ~/cs161/root/testbin/getpidtest The above executable file will be loaded by OS/161 through the p command in the main menu. 9

Step 2 Run the User Program in OS/161 You can follow the instructions below to run the testing program created in Step 1: %cd ~/cs161/root %./sys161 kernel In the menu prompt type: p /testbin/getpidtest 10

System Calls Related to File Systems ~/cs161/src/include/unistd.h 11

System Calls Interface You can find a sample user application here: 12

Data Structure Questions 1. How to represent opened files for each process? 2. Where should you keep the above information? Two-minute group discussion Do not consider data structure for storing and organizing data in files Focus on meta data of files 13

Data Structure Question 1: How to represent opened files for each process? Answer: –The openfile structure –An array (or list) of openfile items: openfileTable –The array is referred by a File Descriptor (FD) Each opened file has an openfile struct Read()/write()/lseek() use file descriptor to operate each opened file 14

What are inside the openfile structure? 15

How will you design the openfile structure? File pointer: –To locate data –A pointer to vnode (How to obtain it?) –vnode is defined in src/kern/include/vnode.h Mode: Read-only, write-only, read-write, etc. Offset Lock Reference count From vfs_open() 16

User-Level Interface for System Calls src/include/unistd.h fid = open( “ fileA ”, flags); … read(fid, buffer, len); 0 stdin 1 stdout 2 stderr 3... openfile Table openfile struct inode Internal File Descriptor In OS161: vnode On-Device File Descriptor 17

Design Question 1 Can a file be opened multiple times? Have two separate openfile struct Indicated by two file descriptors 18

Design Question 2 Will openfile be shared by concurrent threads? No. You do not need to deal with the critical section issue. –Consider this first Yes. You need use lock implemented in project 3 to protect this shared openfile –If you have time, implement this feature –Question: Where to add a lock? in the openfile struct 19

Data Structure Question 2: Where should you keep openfileTable ? Answer: –Place openfileTable in the thread struct –The thread struct is defined in src/kern/include/vnode.h Each opened file has an openfile struct Read()/write()/lseek() use file descriptor to operate each opened file 20

Algorithm Questions: How to design sys_open(filename, flag, retfd) ? Opens a file: create an openfile item Obtain vnode from vfs_open() Initialize offset in openfile File descriptor retfd = Place openfile in openfiletable (Where is the table?) Return the file descriptor of the openfile item. –How to return a value? See sample code sys_getpid() in the document “Adding System Calls to OS/161 21

Algorithm Questions: How does sys_open(filename, flag, retfd) calls vfs_open() ? vfs_open() : prototype in –src/kern/include/vfs.h Check sample code here: –src/kern/test/fstest.c err from vfs_open() struct vnode *vn;... err = vfs_open(name, flags, &vn); 22

Algorithm Questions: How to design int sys_close(fd) ? Use fd to locate the openfile item from openfileTable Are you supporting multiple opens? –Delete openfile if this is the last open Delete openfile from openfileTable –Array: How to delete an item from an array? –Singly-linked list: How to delete from a list? 23

Algorithm Questions: How to design int sys_read(fd, buf, size, *retval) ? To translate the file descriptor number to a file handle object To make a uio record: userspace I/O –See kern/include/uio.h To call VOP_READ –update the current seek position. –Prototype: kern/include/vnode.h –Sample Code: kern/userprog/loadelf.c The file is locked while this occurs. 24

Algorithm Questions: How to design? int sys_read(int fd, userptr_t buf, size_t size, int *retval) Use fd to locate the openfile item from openfileTable Access offset from openfile userio = setup a uio record Call VOP_READ(openfile->vnode, userio) Openfile->offset = userio.offset; Set *retval to the amount read 25

Summary How to test a system call? What are the data structures for opened files? –the openfile structure –openfileTable The Algorithm of sys_open() The Algorithm of sys_close() 26