chapta 10 computer operating system lecture

Upload: karen-miller

Post on 02-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    1/32

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    2/32

    Operating Systems 2

    Basic Functions of File Management Presentlogical (abstract) view of files and directories

    Accessing a disk is very complicated:

    2D or 3D structure, track/surface/sector, seek,

    rotation,

    Hide complexity of hardware devices

    Facilitateefficient use of storage devices

    Optimize access, e.g., to disk

    Supportsharing

    Files persist even when owner/creator is not currently

    active (unlike main memory)

    Key issue: Provide protection (control access)

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    3/32

    Operating Systems 3

    Hierarchical Model of FS

    Physical device organization:

    map file data to disk blocks

    Directory management:

    map logical name tounique Id, file descriptor

    Basic file system:

    open/close files

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    4/32

    Operating Systems 4

    What is a File: Users View

    File name and typeValidname

    Number of characters

    Lower vs upper case, illegal characters

    Extension

    Tied to type of file

    Used by applications

    Filetype recorded in header

    Cannot be changed (even when extension changes)

    Basic types: text, object, load file, directory

    Application-specific types, e.g., .doc, .ps, .html

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    5/32

    Operating Systems 5

    User View of Files Logical file organization

    Most common:byte stream

    Fixed-size or variable-sizerecords

    Addressed

    Implicitly (sequential access to next record)

    Explicitly by position (record#) or key

    a) Fixed Length Record

    b) Variable Length Record

    c) Fixed Length with Key

    d) Variable Length with Key

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    6/32

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    7/32

    Operating Systems 7

    Operations on Files Create/Delete

    Open/Close

    Read/Write (sequential or direct)

    Seek/Rewind (sequential)

    Copy (physical or just link)

    Rename

    Change protection Get properties

    Each involves parts of Directory Management, BFS, or

    Device Organization

    GUI is built on top of these functions

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    8/32

    Operations on Files

    Operating Systems 8

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    9/32

    Operating Systems 9

    Directory Management Directory: hierarchical structure to keep track of files

    Main issues:

    Shape of data

    structure (e.g.

    tree, shortcuts, )

    What info to keep

    about files

    Where to keep it?

    (in directory?)

    How to organizeentries for

    efficiency?

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    10/32

    Operating Systems 10

    File Directories Tree-structured

    Simple search, insert,

    delete operations

    Sharing isasymmetric

    (only one parent)

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    11/32

    Operating Systems 11

    File Directories DAG-structured

    Symmetric sharing,but

    What are semantics ofdelete?

    Any parent can remove file: dangling references

    Only last parent can remove it: Needreference count

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    12/32

    Operating Systems 12

    File Directories DAG-structured

    Allow cycles?

    Ifcycles are allowed: Search is difficult (infinite loops)

    Deletion needs garbage collection (reference count notenough)

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    13/32

    Operating Systems 13

    File Directories Symbolic links (shortcuts)

    Compromise to allow

    sharing but avoid

    cycles

    Forread/write access:Symbolic link is the same as actual link

    Fordeletion: Only symbolic link is deleted

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    14/32

    Operating Systems 14

    File Directories

    How to uniquely name a file in the hierarchy? Path names

    Concatenated local names with delimiter:

    (. or / or \ )

    Absolute path name: start with root

    (/)

    Relative path name: Start with current directory

    (.)

    Notation to move upward in hierarchy

    (..

    )

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    15/32

    Practice navigation Shortest absolute path for F4, F8

    Relative paths when D3 is working directory

    Relative paths when D7 is working directory

    Repeat without symbolic links

    Operating Systems 15

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    16/32

    Operating Systems 16

    Operations on File Directories GUI vs commands

    Create/delete

    List: sorting, wildcards, recursion,information shown

    Change (current,

    working) directory Move

    Rename

    Change protection

    Create/delete link(symbolic)

    Find/search routines

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    17/32

    Operating Systems 17

    Implementation of Directories What information to keep in each entry

    All descriptive information

    Directory can become very large

    Searches are difficult/slow

    Only symbolicname and pointer to descriptor

    Needs an extra disk access to descriptor

    Variable name length?

    Example: BFS

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    18/32

    Operating Systems 18

    Implementation of Directories How toorganize entries

    within directoryFixed-size entries:

    usearray of slots

    Variable-size entries:

    use linkedlist (like BFS)

    Size of directory:fixed or expanding

    Example: Windows 2000

    when # of entries

    exceeds directory size,

    expand using B+-trees

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    19/32

    Revisit file operations Assume:

    descriptors are in a dedicated area directory entries have name and pointer only

    create

    find free descriptor, enter attributes

    find free slot in directory, enter name/pointer

    rename search directory, change name

    delete

    search directory, free entry, descriptor, and data blocks

    copy

    like create, then find and copy contents of file change protection

    search directory, change entry

    Operating Systems 19

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    20/32

    Operating Systems 20

    Basic File System

    Open/Close files Retrieve and set up information forefficient access:

    getfile descriptor

    manageopen file table

    File descriptor (i-node in Unix)

    Owner id

    File type

    Protection information

    Mapping to physical disk blocks

    Time of creation, last use, last modification Reference counter

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    21/32

    Operating Systems 21

    Basic File System

    Open File Table (OFT) keeps track of currently open files open command:

    Search directory for given file

    Verify access rights

    Allocate OFT entry

    Allocate read/write buffers Fill in OFT entry

    Initialization (e.g., current position)

    Information from descriptor(e.g. file length, disk location)

    Pointers to allocated buffers Return OFT index

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    22/32

    Operating Systems 22

    Basic File System

    close command: Flush modified buffers to disk

    Release buffers

    Update file descriptor

    file length, disk location, usage information

    Free OFT entry

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    23/32

    Operating Systems 23

    Revisit file operations read command

    assume file is open forsequential access

    buffered read: current block kept in r/w buffer

    copy from buffer to memory until:

    desired count or end of file is reached:

    update current position, return status or end of buffer is reached:

    write the buffer to disk (if modified)

    read the next block

    continue copying unbufered read: read the entire block containing the

    needed data from disk

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    24/32

    Operating Systems 24

    Revisit file operations write command (buffered)

    write into buffer

    when full, write buffer to disk

    if next block does not exist (file is expanding):

    allocate new block

    update file descriptor

    update bit map (free space on disk) update file length in descriptor

    seek command

    set current position as specified by parameter

    read block containing current position into buffer

    rewind command

    analogous to seek but position is zero

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    25/32

    Operating Systems 25

    Basic File System Example: Unix

    Unbuffered access

    fd=open(name,rw,)

    stat=read(fd,mem,n)

    stat=write(fd,mem,n)

    Buffered accessfp=fopen(name,rwa)

    c=readc(fp)

    // read one char

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    26/32

    Operating Systems 26

    Physical Organization Methods

    Contiguous organization Simple implementation

    Fast sequential access (minimal arm movement)

    Insert/delete is difficult

    How much space to allocate initially

    External fragmentation

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    27/32

    Operating Systems 27

    Physical Organization Methods Linked Organization

    Simple insert/delete, no external fragmentation

    Sequential access less efficient (seek latency)

    Direct access not possible

    Poor reliability (when chain breaks)

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    28/32

    Operating Systems 28

    Physical Organization Methods Linked Variation 1: Keeppointers segregated

    May be cached

    Linked Variation 2: Linksequences of adjacent blocks,

    rather than individual blocks

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    29/32

    Operating Systems 29

    Physical Organization Methods Indexed Organization

    Index table: sequential list of records

    Simplest implementation: keep index list in descriptor

    Insert/delete is easy

    Sequential and direct access is efficient Drawback: file size limited by number of index entries

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    30/32

    Operating Systems 30

    Physical Organization Methods

    Variations of indexingMulti-level index hierarchy

    Primary index points to secondary indices

    Problem: number of disk accesses increases with

    depth of hierarchy

    Incremental indexing

    Fixed number of entries at top-level index

    When insufficient, allocate additional index levels

    Example: Unix, 3-level expansion (see next slide)

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    31/32

    Operating Systems 31

    Physical Organization Methods

    Incremental indexing in Unix

    file size vs. speed of access blocks 0-9: 1 access (direct)

    blocks 10-137: 2 accesses

    blocks 138-16521: 3 acc.

    etc.

  • 8/10/2019 Chapta 10 Computer Operating System Lecture

    32/32

    Operating Systems 32

    Free Storage Space Management

    Similar to main memory management Linked list organization

    Linkingindividual blocks -- inefficient:

    no block clustering to minimize seek operations

    groups of blocks are allocated/released one at a time

    Better: Linkgroups of consecutive blocks

    Bit map organization

    Analogous to main memory

    A single bit per block indicates if free or occupied