File management - Chap 12 - OS

download File management - Chap 12 - OS

of 54

Transcript of File management - Chap 12 - OS

  • 8/10/2019 File management - Chap 12 - OS

    1/54

    2014 by Greg Ozbirn, UTD, foruse with Stalling's 8th Ed. OS book

    1

    Chapter 12

    File Management

    Fall 2014

  • 8/10/2019 File management - Chap 12 - OS

    2/54

    2

    Files and File Systems

    The file system is one of the most important parts of anoperating system.

    Some desirable properties of files include:

    Long-term existence: kept on secondary storage

    Sharable between processes: for shared access

    Structure: some file systems manage the internal

    structure of a file, which can be organized in a way

    suitable for particular applications

  • 8/10/2019 File management - Chap 12 - OS

    3/54

    3

    File Operations

    Create creates a new file and adds it to the directory

    Delete

    remove from the directory and destroyed

    Open allows a process to perform functions on the file

    Close

    the process is no longer allowed to operate on the file

    Read read all or a portion of the file

    Write

    add new data or change existing data in the file

  • 8/10/2019 File management - Chap 12 - OS

    4/54

    4

    File Structure

    Field:

    Basic element of data

    Contains a single value

    Characterized by its length and data type

    Can be fixed length or variable length

    Record:

    Collection of related fields

    Treated as a unit Example: employee record

    Can be variable length if some of the fields are variable

    length, or if the number of fields may vary

  • 8/10/2019 File management - Chap 12 - OS

    5/54

    5

    File Structure

    File

    Collection of similar records

    Treated as a single entity

    Have unique file names

    May restrict access

    Database

    Collection of related data (one or more files)

    Relationships exist among elements Managed by separate DBMS

  • 8/10/2019 File management - Chap 12 - OS

    6/54

    6

    Typical File Operations

    Retrieve_Allto process the whole file

    Retrieve_Oneselects a single record

    Retrieve_Nextmove forward in file

    Retrieve_Previousmove backward in file

    Insert_Onemay require adding at a particular position

    Delete_Onemay need to preserve sequence

    Update_Oneharder if length changes, preserve sequence

    Retrieve_Fewrecords matching a set of criteria

  • 8/10/2019 File management - Chap 12 - OS

    7/54

    7

    Unix Files

    Unix files are simply streams of bytes and do not haveinternal structure as far as the operating system is

    concerned.

    Some OSs such as mainframe systems provide various file

    structures the application can use.

  • 8/10/2019 File management - Chap 12 - OS

    8/54

    8

    File Management System

    Set of system software providing file services to users andapplications.

    Users and applications access files through the file

    management system.

    Programmer does not need to develop file managementsoftware for each application.

  • 8/10/2019 File management - Chap 12 - OS

    9/54

    9

    Objectives for a

    File Management System

    Meet the data management needs and requirements of the

    user (described on next slide).

    Guarantee that the data in the file are valid.

    Optimize performance. Provide I/O support for a variety of storage device types.

    Minimize or eliminate the potential for lost or destroyed

    data.

    Provide a standardized set of I/O interface routines Provide I/O support for multiple users.

  • 8/10/2019 File management - Chap 12 - OS

    10/54

    10

    Meeting User Requirements

    (the first objective listed on previous slide)

    Each user:

    Should be able to create, delete, read, and change files.

    May have controlled access to other users files.

    May control what type of accesses are allowed to the

    users files.

    Should be able to restructure the users files in a form

    appropriate to the problem.

    Should be able to move data between files.

    Should be able to back up and recover the users files in

    case of damage.

    Should be able to access the users files by using symbolic

    names.

  • 8/10/2019 File management - Chap 12 - OS

    11/54

    11

    File System Architecture

    The next slide illustrates a file system architecture.

    The pieces involved are:

    Device driver: communicates directly with hardware

    device.

    Basic file system: handles physical I/O.

    Basic I/O supervisor: responsible for file I/O initiation and

    termination, device selection, I/O scheduling, buffer

    allocation.

    Logical I/O: Enables users and applications to access

    records. Provides record-oriented I/O capability.

    Access method: access files based on their structure and

    method of access.

  • 8/10/2019 File management - Chap 12 - OS

    12/54

    12

  • 8/10/2019 File management - Chap 12 - OS

    13/54

    13

    File Management Functions

    See illustration on next slide: Identify and locate a selected file.

    Use a directory to describe the location of all files plustheir attributes.

    Enforce user access control (shared system). Employ access method on the records.

    Provide blocking for file I/O.

    Block for output and unblock for input.

    Manage secondary storage Allocate files to available blocks.

    Manage free storage of available blocks.

    Scheduling of I/O requests

  • 8/10/2019 File management - Chap 12 - OS

    14/54

    14

  • 8/10/2019 File management - Chap 12 - OS

    15/54

    15

    File Organization and Access

    Criteria for choosing a file organization:

    Rapid Access

    Ease of update

    Economy of storage

    Simple maintenance

    Reliability

    There may be trade-offs between criteria. Priority of criteria depends on how application will use the

    file.

  • 8/10/2019 File management - Chap 12 - OS

    16/54

    16

    File Organization and Access

    There are a large number of file organizations.

    Most actual file organizations are related to one of these

    five fundamental file organizations:

    Pile

    Sequential file

    Indexed sequential file

    Indexed file

    Direct or hashed file

  • 8/10/2019 File management - Chap 12 - OS

    17/54

    17

    Pile

    Data are collected in the order they arrive

    Purpose is to accumulate a mass of data and save it

    Records may have different structures or no structure.

    Data access is by exhaustive search

    May be useful to store data prior to processing

  • 8/10/2019 File management - Chap 12 - OS

    18/54

    18

  • 8/10/2019 File management - Chap 12 - OS

    19/54

    19

    Sequential File

    Fixed format used for records.

    Records are the same length.

    All fields the same (order and length).

    Field names and lengths are attributes of the file.

    One field is the key field

    Uniquely identifies the record

    Records are stored in key sequence

    New records are placed in a log file or transaction file. Log file is periodically merged with the master file.

    Useful in batch processing.

  • 8/10/2019 File management - Chap 12 - OS

    20/54

    20

  • 8/10/2019 File management - Chap 12 - OS

    21/54

    21

    Indexed Sequential File

    File is like a sequential file with key and data.

    Index provides a lookup capability to quickly reach the

    vicinity of the desired record.

    Greatly reduces the time required to access a single record,

    while still providing sequential processing.

    Additions can be handled by an overflow file, which can

    be periodically merged with the main file.

  • 8/10/2019 File management - Chap 12 - OS

    22/54

    22

  • 8/10/2019 File management - Chap 12 - OS

    23/54

    23

    Indexed File

    Uses multiple indexes for different key fields.

    Abandons sequential format with single key.

    Records are accessed only by their index.

    Records can be variable length.

    Exhaustive index has pointers to every record.

    Partial index only has pointers to records having the field

    of interest.

    Useful in applications such as an airline reservation system

    that need to access particular records quickly, but rarely

    need to process them sequentially.

  • 8/10/2019 File management - Chap 12 - OS

    24/54

    24

  • 8/10/2019 File management - Chap 12 - OS

    25/54

    25

    Direct or Hash File

    Turn key value into an address to support direct access ofrecords in the file.

    Gives very rapid access to data.

    Useful if records are only accessed one at a time.

  • 8/10/2019 File management - Chap 12 - OS

    26/54

    B-Trees

    Indexes are often implemented as B-trees.

    The B-tree will have a large branching factor resulting in a

    tree of low height.

    This results in fewer disk accesses to traverse the tree in a

    search.

    26

  • 8/10/2019 File management - Chap 12 - OS

    27/54

    27

    Directories

    The directory contains information about the files,including attributes, location, and ownership.

    The directory is itself a file, owned by the OS and

    managed by the file management system.

    The next slides give information typically found in thedirectory for each file.

  • 8/10/2019 File management - Chap 12 - OS

    28/54

    28

  • 8/10/2019 File management - Chap 12 - OS

    29/54

    29

  • 8/10/2019 File management - Chap 12 - OS

    30/54

    30

    Directory Operations

    Search: find a file in the directory.

    Create file: add entry to directory when a file is created.

    Delete file: remove entry from directory when file is

    deleted.

    List directory: all or a portion may be listed.

    Update directory: change file attributes stored in directory.

  • 8/10/2019 File management - Chap 12 - OS

    31/54

    31

    Directory Structure

    A tree-structure is used for storing the file directory.

    At the top is the master directory, beneath it are each user

    directory.

    Every level may contain files and subdirectories.

  • 8/10/2019 File management - Chap 12 - OS

    32/54

    32

    Directory Naming

    Users refer to files by their symbolic names.

    Each name must be unique.

    In a tree structure, the path to the file helps eliminate

    duplicate name problems.

    Most systems provide for a working directory, where file

    names can be specified relative to it.

    Users typically have a default, or home, directory upon

    logging in.

  • 8/10/2019 File management - Chap 12 - OS

    33/54

    33

    File Sharing

    In a multiuser system, files should be able to be sharedbetween users.

    This presents two issues:

    Access rights

    Simultaneous access

  • 8/10/2019 File management - Chap 12 - OS

    34/54

    34

    File SharingAccess Rights

    When sharing files, we have to have a way of controllingaccess to the file.

    Typically one user is the owner.

    The owner has all of the access rights and may grant rights

    to others.

  • 8/10/2019 File management - Chap 12 - OS

    35/54

    35

    File SharingAccess Rights

    Access rights may be given to different classes of users.

    Typical classes are:

    Specific user

    Group of users

    All:

  • 8/10/2019 File management - Chap 12 - OS

    36/54

    36

    File SharingAccess Rights

    Examples of access rights: None: file is unknown to user.

    Knowledge: user can determine file existence and owner.

    Execution: can execute the file.

    Reading: can read the file. Appending: can only append to end of file.

    Updating: can modify file contents.

    Changing protection: can change access rights.

    Deletion: can remove the file.

    These rights may constitute a hierarchy, with higher levelrights including the lower level ones.

  • 8/10/2019 File management - Chap 12 - OS

    37/54

    37

    File Sharing - Simultaneous Access

    When access is granted to append or update a file to morethan one user, the OS or file management system must

    enforce discipline.

    One approach is to lock the entire file when it is to be

    updated. Another approach is to lock individual records during

    update.

  • 8/10/2019 File management - Chap 12 - OS

    38/54

    38

    Record Blocking

    Users work with a logical view of a file as a set of records. The I/O device works with the physical view of a file as a

    set of blocks.

    Blocking of records is performed when writing data,

    unblocking is performed when reading data.

  • 8/10/2019 File management - Chap 12 - OS

    39/54

    39

    Record Blocking

    Blocking considerations: The larger the block, the more records that are passed in a

    single I/O.

    For sequential access this reduces I/Os, but may result in

    unnecessary data transfer for random access. Typically blocks are of fixed length to simplify the I/O

    transfer.

  • 8/10/2019 File management - Chap 12 - OS

    40/54

    40

    Record Blocking

    There are three blocking methods: Fixed: fixed-length records. May cause internal

    fragmentation.

    Variable-length spanned: variable-length records

    which may span blocks. Permits unlimited record size.May require multiple I/Os.

    Variable-length unspanned: variable-length records

    which do not span blocks. May cause internal

    fragmentation.

  • 8/10/2019 File management - Chap 12 - OS

    41/54

    41

  • 8/10/2019 File management - Chap 12 - OS

    42/54

  • 8/10/2019 File management - Chap 12 - OS

    43/54

    43

    File Allocation

    File allocation issues: Whether to allocate the maximum space required all at

    once, or to allocate space in portions.

    If portions are used, how big should a portion be?

    If portions are used, how to keep track of the portions.

  • 8/10/2019 File management - Chap 12 - OS

    44/54

    44

    Preallocation versus Dynamic Allocation

    Preallocation requires that the maximum file size bedeclared and allocated when the file is created.

    May create waste as users over-estimate required size to

    ensure space needs are met.

    Dynamic allocation allows portions of space to be given tothe file so that it may grow dynamically.

  • 8/10/2019 File management - Chap 12 - OS

    45/54

    45

    Allocation Portion Size

    Two basic methods: Large, variable-length contiguous portion.

    Good performance.

    May cause fragmentation.

    Allocation table is simple, just need pointer to

    beginning and length.

    Small fixed-sized blocks.

    Good flexibility.

    Requires more complicated allocation table to keep

    track of non-contiguous blocks.

  • 8/10/2019 File management - Chap 12 - OS

    46/54

    46

    File Allocation Methods

    Three methods of file allocation: Contiguous allocationa single contiguous set of blocks is

    allocated to a file at the time of file creation. Thus, this is

    a preallocation method of a variable-size portion. May

    require periodic compaction due to fragmentation. Goodfor sequential file access.

    Chained allocationallocate individual blocks. Each

    block contains a pointer to the next block.

    Indexed allocationan index specifies the location of eachblock.

  • 8/10/2019 File management - Chap 12 - OS

    47/54

    47

  • 8/10/2019 File management - Chap 12 - OS

    48/54

    48

  • 8/10/2019 File management - Chap 12 - OS

    49/54

    49

  • 8/10/2019 File management - Chap 12 - OS

    50/54

    50

  • 8/10/2019 File management - Chap 12 - OS

    51/54

    51

  • 8/10/2019 File management - Chap 12 - OS

    52/54

    52

  • 8/10/2019 File management - Chap 12 - OS

    53/54

    53

    Free Space Management

    It is necessary to know what space is available in order toperform allocations.

    A disk allocation table keeps track of available space.

    Techniques:

    Bit tables: each bit represents a block

    Chained free portions: free portions are chained

    together.

    Indexing: index keeps track of every free portion as if it

    was a file.

    Free block list: blocks are numbered and list of free

    block numbers is maintained.

  • 8/10/2019 File management - Chap 12 - OS

    54/54

    based on Stalling's official slides 54

    End of Slides