<<

Operating Systems Lecture #5: Management

Written by David Goodwin based on the lecture series of Dr. Dayou Li and the book Understanding Operating Systems 4thed. by I.M.Flynn and A.McIver McHoes (2006)

Department of Science and Technology, University of Bedfordshire.

Operating Systems, 2013

25th February 2013 Outline

Lecture #5 File Management David Goodwin 1 Introduction University of Bedfordshire 2 Interaction with the file manager Introduction

Interaction with the file manager 3 Files Files

Physical storage 4 Physical storage allocation allocation Directories 5 Directories Access 6 File system compression summary 7 Access

8

9 summary

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction 3

Interaction with the file manager Introduction Files

Physical storage allocation

Directories

File system

Access

Data compression summary

Operating Systems 46 Introduction

Lecture #5 File Management

David Goodwin University of Bedfordshire Introduction 4 ˆ Responsibilities of the file manager Interaction with the file manager 1 Keep track of where each file is stored Files 2 Use a policy that will determine where and how the files will Physical storage be stored, making sure to efficiently use the available storage allocation space and provide efficient access to the files. Directories 3 Allocate each file when a has been cleared for access to File system it, and then record its use. Access 4 Deallocate the file when the file is to be returned to storage, Data compression and communicate its availability to others who may be summary waiting for it.

Operating Systems 46 Definitions

Lecture #5 File Management field is a group of related that can be identified by David Goodwin University of the user with a name, type, and size. Bedfordshire record is a group of related fields. Introduction 5 file is a group of related records that contains Interaction with the file manager information to be used by specific application Files programs to generate reports. This type of file Physical storage allocation contains data and is sometimes called a “flat file”

Directories because it has no connections to other file; unlike File system it has no dimensionality. Access appear to be a type of file, but databases are more Data compression complex. They are groups of related files that are summary interconnected at various levels to give flexibility of access to the data stored. program files contain instructions. data files contain data. directories are listings of filenames and their attributes. Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction Interaction with the 6 Interaction with the file manager

Files Physical storage allocation

Directories

File system

Access

Data compression summary

Operating Systems 46 Interacting with the File Manager

Lecture #5 File Management ˆ David Goodwin User communicates via commands, either embedded in user’s University of Bedfordshire program or submitted interactively by user. ˆ embedded commands are: Introduction ˆ / - pertain to the availability of a file for the Interaction with the 7 file manager program invoking it. ˆ Files / - are I/O commands. ˆ MODIFY - specialised WRITE command for existing data Physical storage allocation files, allows for appending records or for rewriting selected

Directories records in their origional place in the file. ˆ File system interactive commands are:

Access ˆ CREATE / DELETE - deal with the system’s knowledge of

Data compression the file (some systems have the first instance of SAVE command, others OPEN NEW, OPEN... FOR OUTPUT. summary ˆ RENAME - allows users to change the name of an existing file. ˆ COPY - lets users make duplicate copies of existing files. ˆ These commands (and many more) are designed to be simple to make them device independent.

Operating Systems 46 Interaction with the File Manager

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction ˆ Interaction with the 8 Example - READ instruction: file manager 1 Move the read/write heads of the cylinder where the record is Files to be found. Physical storage allocation 2 Wait for the rotational delay until the sector containing the

Directories desired record passes under the read/write head.

File system 3 Activate the appropriate read/write head and read the record.

Access 4 Transfer the record to main memory.

Data compression 5 Send a flag to indicate that the device is free to satisfy summary another request.

Operating Systems 46 Configuration

Lecture #5 File Management David Goodwin ˆ Each storage unit is considered a volume. University of Bedfordshire ˆ Each volume in the system is given a name and other Introduction descriptive information contained on an easy-to-access place Interaction with the 9 (innermaost part of , first sector of outermost track of a file manager ). Volume Descriptor: Files ˆ Creation date - date when volume was created. Physical storage allocation ˆ Pointer to diectory area - indicates first sector where Directories is stored. File system ˆ Pointer to file area - indicates first sector where file is stored. Access ˆ File system code - used to detect volumes with incorrect Data compression formats. summary ˆ Volume name - user-allocated name. ˆ The Master file directory (MFD) is stored immediately after the volume descriptor ˆ lists the names and characteristics of every file contained in that volume.

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager Files Files 10

Physical storage allocation

Directories

File system

Access

Data compression summary

Operating Systems 46 File attributes

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction ˆ Information about files is kept in the ,

Interaction with the which is also maintained on the disk. file manager ˆ Name – only information kept in human-readable form. Files 11 ˆ Identifier – non-human readable unique (usually a Physical storage allocation number). Directories ˆ Type – needed for systems that support different types. File system ˆ Location – pointer to file location on device. Access ˆ Size – current file size. Data compression ˆ Protection – controls who can do reading, writing, executing. summary ˆ Time, date, and user identification – data for protection, security, and usage monitoring.

Operating Systems 46 File operations

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Create Introduction ˆ Interaction with the Write file manager ˆ Read Files 12

Physical storage ˆ Reposition within file – file seek allocation ˆ Directories Delete File system ˆ Truncate Access ˆ Open(Fi) – search the directory structure on disk for entry Data compression F , and move the content of entry to memory. summary i ˆ Close (Fi) – move the content of entry Fi in memory to directory structure on disk.

Operating Systems 46 File types

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Introduction OS recognises and supports file types Interaction with the ˆ helps prevent user mistakes file manager ˆ convenient by automatically doing various jobs after a Files 13 command Physical storage allocation ˆ must define every file type allowed and difficult to create new Directories file types File system ˆ Commonly implemented by using an extension name Access ˆ Data compression Creator attribute used to identify the file type and invoke the summary creator application program ˆ Internal file structure can be indicated by file types

Operating Systems 46 File Types

Lecture #5 File Management

David Goodwin ˆ Two components are common to most filenames: University of Bedfordshire 1 relative filename

Introduction 2 extension (called a suffix in /) Interaction with the ˆ A complete filename identifies a file’s absolute filename; file manager being the long name that includes information. Files 14

Physical storage ˆ there are restrictions on filename with each : allocation ˆ MS-DOS - allows names from one to eight alphanumeric Directories characters, but without spaces File system ˆ most modern operating systems do not have restrictions on Access filenames. Data compression summary ˆ An extension usually 2 or 3 characters long and is separated by a period (.). The purpose is to identify the file type or its contents. ˆ NOTE: some extensions are associated with more than one application

Operating Systems 46 File types – name and extension

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files 15

Physical storage allocation

Directories

File system

Access

Data compression summary

Operating Systems 46 Access methods

Lecture #5 File Management

David Goodwin University of Bedfordshire Introduction ˆ Sequential access Interaction with the file manager ˆ Easiest Files 16 ˆ File searched from its beginning until record is found Physical storage ˆ allocation Direct (relative/random) access

Directories ˆ Only on direct access storage devices

File system ˆ Records identified by their relative address to the beginning

Access of the file Data compression ˆ Indexed access summary ˆ Combines the best of sequential and direct access

Operating Systems 46 Access methods - direct access example

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Records identified by logical address, them relative to the Introduction beginning of the file. Interaction with the file manager ˆ User identifies a field in the record and designates it as Files 17 the key field because it uniquely identifies each record. Physical storage allocation ˆ the program used to store the data follows a set of Directories instructions called a hashing algorithm, that transforms File system each key into a number, the record’s logical address. Access ˆ Data compression This is given to the File Manager, which takes the necessary summary steps to translate the logical address into a physical address (cylinder, surface, and record numbers), preserving the file organisation.

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction Interaction with the Physical storage file manager

Files Physical storage 18 allocation allocation

Directories

File system

Access

Data compression summary

Operating Systems 46 Physical storage allocation

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction Interaction with the ˆ Contigious storage file manager ˆ Files records stored one after another ˆ Physical storage 19 any record can be found and read by knowing its starting allocation address and size Directories ˆ ease of direct access, every part of the file is stored in the File system same compact area Access ˆ file cant be expanded unless there is empty space immediately Data compression following it - also causing fragmentation summary

Operating Systems 46 Physical storage allocation

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Noncontigious storage Introduction ˆ files use any space available on disk Interaction with the ˆ records stored in a contigious manner only if there’s enough file manager empty space Files ˆ any remaining records, and all other additions to the file, are Physical storage 20 allocation stored in other sections of the disk Directories ˆ sometimes called extents of the file - linked together with

File system pointers in one of two ways ˆ Access at storage level - each points to the next one in

Data compression sequence ˆ at directory level - each extent is listed with its physical summary address, size, and a pointer to the next extent. A null pointer indicates it’s the last one. ˆ doesnt support direct access

Operating Systems 46 Physical storage allocation

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager ˆ Indexed storage Files ˆ brings together into an index , the pointers linking every Physical storage 21 allocation extent of that file Directories ˆ every file has its own index block File system ˆ deosn’t improve storage Access ˆ supports direct access Data compression summary

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager Directories Files

Physical storage allocation

Directories 22

File system

Access

Data compression summary

Operating Systems 46 Directory structure

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Directory is a collection of nodes containing information Introduction about all files. Interaction with the ˆ Users are concerned with only the logical directory and its file manager structure. Files ˆ Users can ignore the problems of physically allocating file Physical storage allocation space. Directories 23 ˆ Multiple operating systems are allowed on a computer system. File system ˆ A disk can be split into partitions or volumes, viewed as Access virtual disks. Data compression ˆ Separate disks can be grouped into a large logical structure. summary ˆ Each partition contains information about files in it, kept in entries in a device directory or . ˆ Both the directory structure and the files reside on disk.

Operating Systems 46 A typical file system organisation

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files

Physical storage allocation

Directories 24

File system

Access

Data compression summary

Operating Systems 46 Information on a device directory

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Introduction Name Interaction with the ˆ Type file manager

Files ˆ Address Physical storage ˆ allocation Current length Directories 25 ˆ Maximum length File system ˆ Date last accessed (for archival) Access

Data compression ˆ Date last updated (for ) summary ˆ Owner ID (who pays) ˆ Protection information

Operating Systems 46 Operations performed on a directory

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction Interaction with the ˆ file manager Search for a file Files ˆ Create a file Physical storage allocation ˆ Delete a file Directories 26 ˆ List a directory File system ˆ Access Rename a file Data compression ˆ Traverse the file system summary

Operating Systems 46 Effective organisation of a directory

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager ˆ Efficiency – locating a file quickly Files ˆ Naming – convenient to users Physical storage allocation ˆ Different users can have the same name for different files. Directories 27 ˆ The same file can have several different names. File system ˆ Grouping – logical grouping of files by properties, (.g., all Access Java programs, all games, . . . ) Data compression summary

Operating Systems 46 Single-level directory

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction ˆ A single-level directory for all users Interaction with the file manager

Files

Physical storage allocation

Directories 28

File system

Access Data compression ˆ Naming problem summary ˆ Grouping problem

Operating Systems 46 -structured directories

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files

Physical storage allocation

Directories 29

File system

Access

Data compression summary

Operating Systems 46 Tree-structured directories

Lecture #5 File Management

David Goodwin University of ˆ Bedfordshire Efficient searching ˆ Introduction Grouping capability Interaction with the ˆ file manager Current directory ()

Files cd /spell//prog

Physical storage type list allocation ˆ Directories 30 Absolute path name begins at the root File system ˆ Relative path name defines a path from current directory Access ˆ Creating a new file done in current directory Data compression ˆ summary Delete a file <file-name> ˆ Creating a new subdirectory is done in current directory mkdir

Operating Systems 46 Acyclic graph directories

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files

Physical storage allocation

Directories 31

File system

Access

Data compression summary

Operating Systems 46 Acyclic graph directories

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction Interaction with the ˆ file manager There are shared subdirectories and files. Files ˆ Different absolute path names (aliasing). Physical storage allocation ˆ If words deletes list → dangling pointer. Directories 32 Solutions: File system ˆ Backpointers, so we can delete all pointers. Access ˆ Backpointers using a daisy chain organisation. Data compression ˆ Entry-hold-count solution. summary

Operating Systems 46 General graph directories

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files

Physical storage allocation

Directories 33

File system

Access

Data compression summary

Operating Systems 46 General graph directories

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager ˆ Files How do we guarantee no cycles? Physical storage ˆ Allow only links to file not subdirectories. allocation ˆ Garbage collection. Directories 34 ˆ Every time a new link is added, a cycle detection algorithm is File system used to determine whether it is OK. Access

Data compression summary

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager File system Files

Physical storage allocation

Directories

File system 35

Access

Data compression summary

Operating Systems 46 File system mounting

Lecture #5 File Management

David Goodwin University of Bedfordshire Introduction ˆ A file system must be mounted before it can be accessed. Interaction with the file manager ˆ An unmounted file system (device) is mounted at a Files point. Physical storage allocation ˆ Typical example - UNIX systems Directories e.g. user’s directories can be mounted as File system 36 /home or /users Access and thus a user’s directory may become Data compression /home/user01 or /users/user01 summary where /home or /users is the mount point

Operating Systems 46 File system mounting

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager

Files

Physical storage allocation

Directories

File system 37

Access

Data compression summary ˆ a) Existing ˆ b) Unmounted partition ˆ ) Mounted at users/

Operating Systems 46

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager ˆ Sharing of files on multi-user systems is desirable. Files ˆ Physical storage Sharing may be done through a protection scheme. allocation ˆ On distributed systems, files may be shared across a network. Directories File system 38 ˆ (NFS) is a common distributed Access file-sharing method. Data compression summary

Operating Systems 46 Protection

Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction ˆ File owner/creator should be able to control: Interaction with the ˆ file manager What can be done ˆ Files By whom Physical storage ˆ Types of access allocation ˆ Directories Read ˆ File system 39 Write ˆ Access Execute ˆ Data compression Append ˆ summary Delete ˆ List

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager Access Files

Physical storage allocation

Directories

File system

Access 40

Data compression summary

Operating Systems 46 Access lists and groups

Lecture #5 File Management ˆ David Goodwin of access: read, write, execute University of Bedfordshire ˆ Three classes of users

Introduction 1 a) owner access 7 → 1 1 1 (RWX) Interaction with the 2 b) group access 6 → 1 1 0 (RWX) file manager 3 c) public access 1 → 0 0 1 (RWX) Files ˆ Physical storage Ask manager to create a group (unique name), say G, and allocation add some users to the group. Directories ˆ File system For a particular file (say game) or subdirectory, define an

Access 41 appropriate access.

Data compression summary

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager Data compression Files

Physical storage allocation

Directories

File system

Access

Data compression 42 summary

Operating Systems 46 Data compression

Lecture #5 File Management

David Goodwin University of Bedfordshire ˆ Technique to save space in files Introduction Interaction with the ˆ Records with repeated characters file manager ADAMSbbbbbbbbbb → ADMSb10 Files

Physical storage 300000000 → 3#8 allocation ˆ Repeated terms represented with symbols Directories Smith, Betty; Smith, Gino; Smithberger, John; Smithbren, Ali File system

Access →

Data compression 43 Smith, Betty; 7Gino; 5berger, John; 6ren, Ali summary ˆ Front-end compression ˆ Trade-off - Storage space saving at cost of processing time

Operating Systems 46 Lecture #5 File Management

David Goodwin University of Bedfordshire

Introduction

Interaction with the file manager summary Files

Physical storage allocation

Directories

File system

Access

Data compression summary 44

Operating Systems 46 Key Terms

Lecture #5 File Management

David Goodwin University of absolute filename Bedfordshire contigious storage Introduction

Interaction with the current directory file manager data compression Files Physical storage data file allocation

Directories database File system device independent Access direct record organisation Data compression summary 45 directory extension field file

Operating Systems 46 Key Terms

Lecture #5 File Management David Goodwin file descriptor University of Bedfordshire hashing algorithm Introduction indexed sequential record organisation Interaction with the file manager key field Files logical address Physical storage allocation master file directory Directories

File system noncontigious storage Access program file Data compression record summary 46 relative address relative filename sequential record organisation volume

Operating Systems 46