Lecture 17 files and directories

Pdf File 704.65 KByte, 33 Pages

11/1/16

CS 422/522 Design & Implementation of Operating Systems

Lecture 17: Files and Directories

Zhong Shao Dept. of Computer Science

Yale University

Acknowledgement: some slides are taken from previous versions of the CS422/522 lectures taught by Prof. Bryan Ford and Dr. David Wolinsky, and also from the official set of slides accompanying the OSPP textbook by Anderson and Dahlin.

The big picture

Lectures before the fall break:

? Management of CPU & concurrency ? Management of main memory & virtual memory

Current topics --- "Management of I/O devices"

? Last week: I/O devices & device drivers ? Last week: storage devices ? This week: file systems

* File system structure * Naming and directories * Efficiency and performance * Reliability and protection

1

11/1/16

This lecture

Implementing file system abstraction

Physical Reality block oriented physical sector #'s no protection

data might be corrupted if machine crashes

File System Abstraction byte oriented named files users protected from each other robust to machine failures

File system components

Disk management

? Arrange collection of disk blocks into files

Naming

? User gives file name, not track or sector number, to locate data

Security / protection

? Keep information secure

Reliability/durability

? When system crashes, lose stuff in memory, but want files to be durable

User

File Naming

File access

Disk management

Disk drivers

2

11/1/16

User vs. system view of a file

User's view

? Durable data structures

System's view (system call interface)

? Collection of bytes (Unix)

System's view (inside OS):

? Collection of blocks ? A block is a logical transfer unit, while a sector is the physical

transfer unit. Block size >= sector size.

File structure

None - sequence of words, bytes Simple record structure

? Lines ? Fixed length ? Variable length Complex structures ? Formatted document ? Relocatable load file Can simulate last two with first method by inserting appropriate control characters. Who decides: ? Operating system ? Program

3

11/1/16

File attributes

Name ? only information kept in human-readable form. Type ? needed for systems that support different

types. Location ? pointer to file location on device. Size ? current file size. Protection ? controls who can do reading, writing,

executing. Time, date, and user identification ? data for

protection, security, and usage monitoring. Information about files are kept in the directory

structure, which is maintained on the disk.

File operations

create write read reposition within file ? file seek delete truncate open(Fi) ? search the directory structure on disk for

entry Fi, and move the content of entry to memory. close (Fi) ? move the content of entry Fi in memory to

directory structure on disk.

4

File types ? name, extension

F ile T ype

E xecutable O bject S ource code B atch T ext Word proces s or L ibrary P rint or view A rc hiv e

Usual extens ion

F unction

exe, com, bin or none obj, o

c, p, pas, 177, asm, a bat, s h

txt, doc

ready-to-run machinelanguage program complied, machine language, not linked s ource code in various la ng ua g e s commands to the command interpreter textual data documents

wp, tex, rrf, etc. lib, a

various word-proces s or forma ts libraries of routines

ps , dvi, gif

AS C II or binary file

arc, z ip, tar

related files grouped into one file, s ometimes compres s ed.

11/1/16

Data structures for a typical file system

Process control block

Open

file pointer array

. . .

Open file table

(systemwide)

File descriptors (Metadata)

File system info File

descriptors

Directories

File data

5

11/1/16

Open a file

File name lookup and authenticate

Copy the file descriptors into the in-memory data structure, if it is not in yet

Create an entry in the open file table (system wide) if there isn't one

Create an entry in PCB

Link up the data structures

Return a pointer to user

fd = open( FileName, access)

PCB

Allocate & link up

data structures

Open file table

File name lookup & authenticate

Metadata File system on disk

Translating from user to system view

What happens if user wants to read 10 bytes from a file starting at byte 2? ? seek byte 2 ? fetch the block ? read 10 bytes

What happens if user wants to write 10 bytes to a file starting at byte 2? ? seek byte 2 ? fetch the block ? write 10 bytes ? write out the block

Everything inside file system is in whole size blocks ? Even getc and putc buffers 4096 bytes ? From now on, file is collection of blocks.

6

Download Pdf File