CSCE 313 Introduction to Computer Systems

Similar documents
The UNIX File System. File Systems and Directories UNIX inodes Accessing directories Understanding links in directories.

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018

CPSC 410/611: File Management. What is a File?

Outline. File Systems. File System Structure. CSCI 4061 Introduction to Operating Systems

OPERATING SYSTEMS: Lesson 12: Directories

CSE 333 SECTION 3. POSIX I/O Functions

Unix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu

CSE 333 SECTION 3. POSIX I/O Functions

File and Directories. Advanced Programming in the UNIX Environment

Chapter 11: File-System Interface

Operating System Labs. Yuanbin Wu

Last Week: ! Efficiency read/write. ! The File. ! File pointer. ! File control/access. This Week: ! How to program with directories

Chapter 10: File-System Interface. Operating System Concepts with Java 8 th Edition

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

File-System. File Concept. File Types Name, Extension. File Attributes. File Operations. Access Methods. CS307 Operating Systems

System Programming. Introduction to Unix

Chapter 4 - Files and Directories. Information about files and directories Management of files and directories

Operating System Labs. Yuanbin Wu

The UNIX File System

Chapter 10: File-System Interface

Operating Systems Lab

The UNIX File System

Overview. Unix System Programming. Outline. Directory Implementation. Directory Implementation. Directory Structure. Directories & Continuation

Chapter 11: File-System Interface

Chapter 10: File-System Interface

structs as arguments

CS3600 SYSTEMS AND NETWORKS

CSC 271 Software I: Utilities and Internals

Exploring the file system. Johan Montelius HT2016

Lecture 10 File Systems - Interface (chapter 10)

Part Four - Storage Management. Chapter 10: File-System Interface

F 4. Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes

Lecture 21 Systems Programming in C

CSCI-E28 Lecture 3 Outline. Directories, File Attributes, Bits, File Operations. Write our own versions of Unix programs

Sharing may be done through a protection scheme. Network File System (NFS) is a common distributed file-sharing method

File Systems: Interface and Implementation

File Systems: Interface and Implementation

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 10: FILE SYSTEM

There is a general need for long-term and shared data storage: Files meet these requirements The file manager or file system within the OS

CMSC421: Principles of Operating Systems

File Systems: Interface and Implementation

CS240: Programming in C

Chapter 10: File-System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

File-System Interface. File Structure. File Concept. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

Chapter 11: File-System Interface

Chapter 10: File-System Interface. Operating System Concepts 8 th Edition

File Systems. CS170 Fall 2018

FAT (32 KB) 216 * 215 = 231 = 2GB

UNIT V SECONDARY STORAGE MANAGEMENT

Chapter 10: File System. Operating System Concepts 9 th Edition

[6 marks] All parts of this question assume the following C statement. Parts (b) through (e) assume a variable called ptrs.

Chapter 11: File-System Interface. File Concept. File Structure

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Chapter 9: File System Interface

CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Chapter 11: File System Interface Capítulo 10 no livro adotado!

Chapter 10: File-System Interface

Chapter 6 Storage Management File-System Interface 11.1

Chapter 1. Introduction

CSE 410: Systems Programming

CSci 4061 Introduction to Operating Systems. File Systems: Basics

CS , Spring Sample Exam 3

CSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19

Chapter 7: File-System

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

File IO and command line input CSE 2451

Chapter 11: File-System Interface. File Concept. File Structure

Chapter 11: File System Interface

Chapter 10: File System

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Chapter 11: File-System Interface

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100

Operating Systems. No. 9 ศร ณย อ นทโกส ม Sarun Intakosum

Principles of Operating Systems

File Systems. q Files and directories q Sharing and protection q File & directory implementation

Introduction. Files. 3. UNIX provides a simple and consistent interface to operating system services and to devices. Directories

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

File System Definition: file. File management: File attributes: Name: Type: Location: Size: Protection: Time, date and user identification:

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

Chapter 11: File-System Interface

Chapter 11: File-System Interface. Long-term Information Storage. File Structure. File Structure. File Concept. File Attributes

CSCI-E28 Lecture 4 Outline. Internal Structure of Files, Directories, File Systems. Work from user view tosystem view, write pwd

2009 S2 COMP File Operations

Chapter 11: File-System Interface. Operating System Concepts 9 th Edition

Introduction to Computer and Program Design. Lesson 6. File I/O. James C.C. Cheng Department of Computer Science National Chiao Tung University

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

OPERATING SYSTEMS: Lesson 2: Operating System Services

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

File Systems. Today. Next. Files and directories File & directory implementation Sharing and protection. File system management & examples

CITS2002 Systems Programming. Identifying related data. 1 next CITS2002 CITS2002 schedule. Let's consider the st project for CITS1002.

CS360 Midterm 2 Spring, 2016 James S. Plank March 10, 2016

Do not turn the page until 5:00.

Slide Set 18. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

csci-e28 lecture 4samples page 1

Transcription:

CSCE 313 Introduction to Computer Systems Instructor: Dr. Guofei Gu http://courses.cse.tamu.edu/guofei/csce313 The UNIX File System File Systems and Directories Accessing directories UNIX s Understanding links in directories File protection/access control Reading: R&R, Ch 5 1

A Typical File-system Organization Directories Large amounts of data: Partition and structure for easier access. High-level structure: partitions in MS-DOS minidisks in MVS/VM file systems in UNIX Directories: Map file name to directory entry (basically a symbol table). 2

Organize the Directory (Logically) to Obtain Efficiency locating a file quickly Naming convenient to users Two users can have same name for different files The same file can have several different names Grouping logical grouping of files by properties, (e.g., all Java programs, all games, ) Single-level directory: directory Directory Structures file Problems: limited-length file names multiple users? not composable (how do you combine multiple file systems?) 3

Two-Level Directories master directory user1 user2 user3 user4 user directories file Path names Location of system files special directory search path Tree-Structured Directories user bin pub user1 user2 user3... find count ls cp bin mail netsc openw bin demoinclude... create subdirectories new concepts: gcc gdb xmt xinit xman xmh xterm current directory path names: complete vs. relative search paths 4

Generalized Tree Structures share directories and files keep them easily accessible user bin pub user1 user2 user3... find count ls cp xman bin mail opwin netsc bin demo incl... xinit gcc gdb xmt xinit xman xmh xterm Links: File name that, when referred, affects file to which it was linked. (hard links, symbolic links) Problems: consistency, deletion Why links to directories only allowed for system managers? UNIX Directory Navigation: current directory #include <unistd.h> char * getcwd(char * buf, size_t size); /* get current working directory */ Example: void main(void) { char mycwd[path_max]; } if (getcwd(mycwd, PATH_MAX) == NULL) { perror ( Failed to get current working directory ); return 1; } printf( Current working directory: %s\n, mycwd); return 0; 5

UNIX Directory Navigation: directory traversal #include <dirent.h> DIR * opendir(const char * dirname); /* returns pointer to directory object */ struct dirent * readdir(dir * dirp); /* read successive entries in directory dirp */ int closedir(dir *dirp); /* close directory stream */ void rewinddir(dir * dirp); /* reposition pointer to beginning of directory */ #include <dirent.h> Directory Traversal: Example int main(int argc, char * argv[]) { struct dirent * direntp; DIR * dirp; if (argc!= 2) { fprintf(stderr, Usage: %s directory_name\n, argv[0]); return 1; } if ((dirp = opendir(argv[1])) == NULL) { perror( Failed to open directory ); return 1; } } while ((direntp = readdir(dirp))!= NULL) printf(%s\n, direntp->d_name); while((closedir(dirp) == -1) && (errno == EINTR)); return 0; 6

Interlude: Logical View of File Management user file structure directory management access control records access method physical blocks in memory blocking physical blocks on disk disk scheduling file allocation Unix File System Implementation: s file information: - size (in bytes) - owner UID and GID - relevant times (3) - link and block counts - permissions 0 multilevel indexed allocation table multilevel allocation table direct 9 10 11 12 single indirect double indirect triple indirect 7

Directory Implementation file information: - size (in bytes) - owner UID and GID - relevant times (3) - link and block counts - permissions Where is the filename?! Name information is contained in separate Directory File, which contains entries of type: (name of file, 1 number of file) 12345 name myfile.txt 12345 1 23567 block 23567 some text in the file 1 More precisely: Number of block that contains. Hard Links directory entry in /dira name 12345 name1 directory entry in /dirb name 12345 name2 shell command ln /dira/name1 /dirb/name2 12345 21 23567 block 23567 some text in the file is typically implemented using the link system call: #include <stdio.h> #include<unistd.h> if (link( /dira/name1, /dirb/name2 ) == -1) perror( failed to make new link in /dirb ); 8

Hard Links: unlink directory entry in /dira name 12345 name1 directory entry in /dirb name 12345 name2 12345 12 0 23567 block 23567 some text in the file #include <stdio.h> #include<unistd.h> if (unlink( /dira/name1 ) == -1) perror( failed to delete link in /dira ); if (unlink( /dirb/name2 ) == -1) perror( failed to delete link in /dirb ); Symbolic (Soft) Links directory entry in /dira name 12345 name1 directory entry in /dirb name 13579 name2 Only count hard links! 12345 block 23567 13579 block 3546 1 some text in the file 1 /dira/na me1 shell command ln -s /dira/name1 /dirb/name2 23567 3546 is typically implemented using the link system call: #include <stdio.h> #include<unistd.h> if (symlink( /dira/name1, /dirb/name2 ) == -1) perror( failed to create symbolic link in /dirb ); 9

Exercises You execute ln /dira/name1 /dirb/name2 and then use a text editor Open file /dira/name1 Read file into memory Close /dira/name1 Modify the memory image of the file Unlink /dira/name1 Open file /dira/name1 with create and write flags Write the contents of memory to file Close /dira/name1 What exactly happened during the above process? What if the first step is ln s /dira/name1 /dirb/name2? Protection File owner/creator should be able to control: what can be done by whom Types of access Read Write Execute Append Delete List 10

Access Lists and Groups Mode of access: read, write, execute Three classes of users RWX a) owner access 7 Þ 1 1 1 RWX b) group access 6 Þ 1 1 0 RWX c) public access 1 Þ 0 0 1 Ask manager to create a group (unique name), say G, and add some users to the group. For a particular file (say game) or subdirectory, define an appropriate access. owner group public Attach a group to a file chmod 761 game chgrp G game Windows XP Access-control List Management 11

A Sample UNIX Directory Listing 12