Operating Systems Lecture #5: File 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 Computer 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 File system Access 6 File system Data compression summary 7 Access
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 user 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 bytes 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 databases it has no dimensionality. Access database 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 file manager 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 OPEN / CLOSE - pertain to the availability of a file for the Interaction with the 7 file manager program invoking it. Files READ / WRITE - 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 Volume 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 CD, first sector of outermost track of a file manager disk pack). Volume Descriptor: Files Creation date - date when volume was created. Physical storage allocation Pointer to diectory area - indicates first sector where directory 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 directory structure,
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 tag (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 UNIX/Linux) Interaction with the A complete filename identifies a file’s absolute filename; file manager being the long name that includes path information. Files 14
Physical storage there are restrictions on filename with each operating system: 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 format 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 extent 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 block, 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 volume table of contents. 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 dump) 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, (e.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 Tree-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 (working directory)
Files cd /spell/mail/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 rm <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 mount 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 c) Mounted at users/
Operating Systems 46 File sharing
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 Network File System (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 Mode 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