View on GitHub

Notes

reference notes

File System and Structure

What is a file?

In most application the input to the application is by means of a file, and in virtually all applications output is saved in a file for longterm storage and for later access.

Users has to be able to access files, save them and maintain the integrity of their contents.

In managing files, all operating systems provide file management system (FMS).

FILE: Data collections created by users

3 desirable properties of files:

File Systems

The File System is one of the most important parts of the OS to a user

Provide a means to store:

  1. organized data
  2. a collection of authorized operations that can be performed on files

6 Operations:

  1. Create - A new file is defined and positioned within the structure of files.
  2. Delete - A file is removed from the file structure and destroyed.
  3. Open - An existing file is declared to be “opened” by a process, allowing the process to perform functions on the file.
  4. Close - The file is closed with respect to a process, so that the process no longer may perform functions on the file, until the process opens the file again.
  5. Read - A process reads all or a portion of the data in a file.
  6. Write - A process updates a file, either by adding new data that expands the size of the file or by changing the values of existing data items in the file.

File Structure

Four terms are commonly used when discussing files:

  1. Field
    • basic element of data
    • contains a single value
    • length and data type
  2. Record
    • collection of related fields that can be treated as a unit by some application program
    • fixed or variable length
  3. File
    • collection of similar records
    • treated as a single entity
    • may be referenced by name
    • access control restrictions usually apply at the file level
  4. Database
    • collection of related data
    • relationships among elements of data are explicit
    • designed for use by a number of different applications
    • consists of one or more types of files

File Structure

File Management System (FMS)

FMS: set of system software that provides services to users and applications in the use of files

Minimal User Requirements

Each user:

  1. should be able to create, delete, read, write and modify files
  2. may have controlled access to other users’ files
  3. may control what type of accesses are allowed to the files
  4. should be able to restructure the files in a form appropriate to the problem
  5. should be able to move data between files
  6. should be able to back up and recover files in case of damage
  7. should be able to access his or her files by name rather than by numeric identifier

FMS objectives

  1. Meet the data management needs of the user
  2. Guarantee that the data in the file are valid
  3. Optimize performance (how will the file be accessed/shared?)
  4. Provide I/O support for a variety of storage device types
  5. Minimize the potential for lost or destroyed data
  6. Provide a standardized set of I/O interface routines to user processes
  7. Provide I/O support for multiple users in the case of multiple-user systems

Software Organization for Files

Software Organization for Files

Device Drivers

Basic File System

Basic I/O Supervisor

Logical I/O

Access Method

File Management Functions

How files are stored and organized by the OS? Method related to file organization :The piles, index, sequential index etc.

File Organization and Access

File Organization: the logical structuring of the records as determined by the way in which they are accessed

In choosing a file organization, several criteria are important (more the one method can be chosen):

  1. Short access time
  2. Ease of update
  3. Economy of storage
  4. Simple maintenance
  5. Reliability

Priority of criteria depends on the application that will use the file

File Organization Types

The Pile

The Sequential File

The Indexed Sequential File

For example, depending on needs file can be indexed based on:

The Indexed File

Direct or Hashed File

File Directories

Associated with any file management system and collection of files is a file directory.

Directory contains information about files

  1. Attributes – size, format, creation date
  2. Location – where is it on the disc, drives
  3. Ownership – creator, owner, editor

Directory itself is a file owned by the operating system

Operations Performed on a Directory

Directory Schemes

Two-Level Scheme

Hierarchical Scheme

File Sharing and Access Rights

Two issues arise when allowing files to be shared among a number of users:

Access Rights

Classes of Users

Simultaneous Access

Record Blocking

Blocks are the transfer unit of I/O with secondary storage

Given the size of a block, three methods of blocking can be used:

  1. Fixed-Length Blocking
    • fixed-length records are used, and an integral number of records are stored in a block
    • Internal fragmentation – unused space at the end of each block
  2. Variable-Length Unspanned Blocking
    • variable-length records are used, but spanning is not employed
  3. Variable-Length Spanned Blocking
    • variable-length records are used and are packed into blocks with no unused space

Fixed-Length Blocking

  1. Assumes that the file is large enough to span two tracks.
  2. Wasted space due to block size incompatibility

Variable-Length Unspanned Blocking

  1. The record size are varied and cannot span multiple tracks
  2. Wasted space in most block because of the inability to use the remainder of a block if the next record is larger than the remaining unused space

Secondary Storage Management

File Allocation

On secondary storage, a file consists of a collection of blocks

The operating system or file management system is responsible for allocating blocks to files

  1. The approach taken for file allocation may influence the approach taken for free space management
  2. Space is allocated to a file as one or more portions (contiguous set of allocated blocks)

File Allocation Table (FAT)

Preallocation vs Dynamic Allocation

Preallocation:

Dynamic Allocation:

Portion Size

“Portion” refer to space is allocated to a file as one or more contagious units

There is a trade-off between efficiency from the point of view of a single file versus overall system efficiency

Items to be considered:

  1. Contiguity of space increases performance
    • Especially for Retrieve_Next operations, and greatly for transactions running in a transaction-oriented operating system
  2. Having a large number of small portions increases the size of tables needed to manage the allocation information
    • Having fixed-size portions simplifies the reallocation of space
    • Having variable-size or small fixed-size portions minimizes waste of unused storage due to overallocation

Alternatives based on the considerations

Two major alternatives:

  1. Variable, large contiguous portions (Dynamic)
    • provides better performance
    • the variable size avoids waste
    • the file allocation tables are small
  2. Blocks (Fixed)
    • small fixed portions provide greater flexibility
    • they may require large tables or complex structures for their allocation
    • contiguity has been abandoned as a primary goal
    • blocks are allocated as needed

File Allocation Methods

Contiguous File Allocation

Linked / Chained Allocation

Indexed Allocation with Fixed Size Block

Indexed Allocation with Variable Size Portions