74
Chapter 9: File-System Interface 11/15/2014 SDM SVV OS 1 Mr. S. V. Viraktamath Dept of E&CE, SDMCT, Dharwad [email protected]

O svv92014

Embed Size (px)

Citation preview

Page 1: O svv92014

Chapter 9: File-System Interface

11/15/2014 SDM SVV OS 1

Mr. S. V. Viraktamath

Dept of E&CE,

SDMCT, Dharwad

[email protected]

Page 2: O svv92014

11/15/2014 SDM SVV OS 2

Page 3: O svv92014

Chapter 10: File-System Interface

• File Concept

• Access Methods

• Directory Structure

• File-System Mounting

• File Sharing

• Protection

Page 4: O svv92014

Introduction

• So far - Discussed

– CPU scheduling

– Process issues- Critical section problem

– Deadlock

– Main memory management

– Virtual memory

• File system is a most visible aspect of OS.

• It provides the mechanism for on-line storage of and access to both data and programs (OS+User)

11/15/2014 SDM SVV OS 5

Page 5: O svv92014

• File?

• Directories?

• Partitions?

• In this topic various aspects of files and the

major directory structures.

11/15/2014 SDM SVV OS 6

Page 6: O svv92014

• Storage Medias

• Magnetic disks, magnetic tapes, and optical

disks.

• Files are mapped, by the operating system,

onto physical devices.

• These storage devices are usually nonvolatile.

• A file is a named collection of related

information that is recorded on secondary

storage.

11/15/2014 SDM SVV OS 7

Page 7: O svv92014

Summary

• File system is a most visible aspect of OS.

• A file is an abstract data type defined and

implemented by the operating system.

• Collection of files Directories Partitions.

• Storage medias magnetic disks, magnetic

tapes, and optical disks

• Files are mapped by OS onto physical devices.

11/15/2014 SDM SVV OS 8

Page 8: O svv92014

File

• A file is the smallest allotment of logicalsecondary storage.

• Data cannot be written to secondary storageunless they are within a file.

• Data files may be numeric, alphabetic,alphanumeric, or binary.

• In general, a file is a sequence of bits, bytes,lines, or records.

• The information in a file is defined by itscreator

11/15/2014 SDM SVV OS 9

Page 9: O svv92014

• A file has a certain defined structure

according to its type.

• A text file is a sequence of characters

organized into lines

• Source file, Object file, executable file ?

11/15/2014 SDM SVV OS 10

Page 10: O svv92014

File Attributes

• A File name is usually a string of characters,

such as example1.c

• When a file is named, it becomes independent

of the process, the user, and even the system

that created it.

• A file has certain attributes

– Name -Type - Size

– Location - Protection

– Time, Date and user identification..

11/15/2014 SDM SVV OS 11

Page 11: O svv92014

Snapshot

11/15/2014 SDM SVV OS 12

Page 12: O svv92014

Snapshot of directory

11/15/2014 SDM SVV OS 13

Page 13: O svv92014

File operations

• The operating system can provide system calls

to create, write, read, reposition, delete, and

truncate files.

• Truncating a file: The user may want to erase

the contents of a file but keep its attributes.

• Other common operations - appending new

information to the end of an existing file and

renaming an existing file.

• Searching the directory for the file..

11/15/2014 SDM SVV OS 14

Page 14: O svv92014

Open files

• The OS keeps a small table containing

information about all open files (the open-file

table).

• File operation requested – no searching is

required

11/15/2014 SDM SVV OS 15

Page 15: O svv92014

Types of files

• A common technique for implementing file

types is to include the type as part of the file

name.

• The name is split into two parts-a name and an

extension, usually separated by a period

character. (Name and family name/address, USN)

• User and OS can understand which type of file

it is.

11/15/2014 SDM SVV OS 16

Page 16: O svv92014

• MS-DOS, a name can consist of up to eight

characters followed by a period and terminated

by an extension of up to three characters.

• A file with a .com, .exe, or .bat extension can

be executed.

• Assemblers expect source files to have an .asm

extension,

• The word processor expects its file to end with

a .doc extension..

11/15/2014 SDM SVV OS 17

Page 17: O svv92014

Common file types

11/15/2014 SDM SVV OS 18

Page 18: O svv92014

• File names

– Operatingsystem1

– ↓↨♥♣•◘¶☻▬↨

11/15/2014 SDM SVV OS 19

Page 19: O svv92014

Access Methods

• Files store information.

• This information must be accessed and read

into computer memory.

• Methods

– Sequential Access

– Direct Access

– Other Access Methods ..

11/15/2014 SDM SVV OS 20

Page 20: O svv92014

Access Methods

• Sequential Access

– Simplest access method

• Used : editors and compilers usually access

files in this fashion

• Bulk operations –reads and writes.

• read next; write next;

• no read after last write

11/15/2014 SDM SVV OS 21

Page 21: O svv92014

Sequential-access file.

• Sequential access is based on a tape model of a

file.

11/15/2014 SDM SVV OS 22

Page 22: O svv92014

Direct Access

• This method is based on a disk model of a file

• Disks allow random access to any file block

• A direct-access file allows arbitrary blocks to be

read or written.

• may read block 14, then read block 53, back to 7

• read n, where n is the block number, rather than

read next, and write n rather than write next.

11/15/2014 SDM SVV OS 23

Page 23: O svv92014

Other access method

• Can be built on top of a direct-access method.

• An index in the back of a book- like index -

contains pointers to the various blocks.

• first search the index, and then use the pointer

11/15/2014 SDM SVV OS 24

Page 24: O svv92014

Directory Structure

• The file systems of computers can beextensive.

• How many files may be there in u r system?

• Some systems store millions of files onterabytes of disk.

• First, disks are split into one or morepartitions-- files and directories reside.

• Partitions can also store multiple operatingsystems, allowing a system to boot and runmore than one.

11/15/2014 SDM SVV OS 25

Page 25: O svv92014

A typical file-system organization

11/15/2014 SDM SVV OS 26

Page 26: O svv92014

The operations - on a directory

• Search for a file- search directory for a file

• Create a file- new file added to directory

• Delete a file

• List a directory- able to list the files in a directory

• Rename a file- content changes

• Traverse the file system- the file can be copied

to tape.

• ………………………..

11/15/2014 SDM SVV OS 27

Page 27: O svv92014

Single-Level Directory

• The simplest directory structure

• All files are contained in the same directory

• As the number of files and users increases-limitations

11/15/2014 SDM SVV OS 28

All Users-common folder

Page 28: O svv92014

Two-Level Directory

• Create a separate directory for each user.

• Each user has her own user file directory(UFD)

• It lists only the files of a single user. It isolatesone user from another user.

11/15/2014 SDM SVV OS 29

Page 29: O svv92014

• When a user job starts or a user logs in, the

system's master file directory (MFD) is

searched.

• The MFD is indexed by user name or account

number, points to the UFD for that user. (C pgms)

To name a particular file uniquely we must give

both user name and file name.

System files stored in directory user 0.

Can have the same file name for different user

Efficient searching

11/15/2014 SDM SVV OS 30

Page 30: O svv92014

Tree-Structured Directories

11/15/2014 SDM SVV OS 31

Page 31: O svv92014

MS DOS –structures files as a tree

Tree is most common directory structure.

Tree has root directory.

Path name is path from root, through all

subdirectories to a specified file.

A directory contains a set of files or

subdirectories.

• Each user has a current directory.

11/15/2014 SDM SVV OS 32

Page 32: O svv92014

• Absolute path name: It begins at the root and follows a path down to the specified file, giving the directory names on the path.

• A relative path name:

Defines a path from the current directory.

Ex. Current directory root/spell/mail then

• Absoluteroot/spell/mail/prt/first

• Relative prt/first

• If directory is empty, it can be deleted. (MSDOS)

• Unix rm command removes /deletes a directory.

11/15/2014 SDM SVV OS 33

Page 33: O svv92014

Acyclic-Graph Directories

• Consider two programmers who are working

on a joint project.

• There may be common subdirectory between

them.

• An acyclic graph allows directories to have

shared subdirectories and files.

• The same file or subdirectory may be in two

different directories.

11/15/2014 SDM SVV OS 34

Page 34: O svv92014

11/15/2014 SDM SVV OS 35

Page 35: O svv92014

• A tree structure prohibits the sharing of files or

directories.

• An acyclic graph allows directories to have

shared subdirectories and files.

• An acyclic graph, that is, a graph with no

cycles, is a natural generalization of the tree

structured directory scheme.

11/15/2014 SDM SVV OS 36

Page 36: O svv92014

• With a shared file, only one actual file exists,

so any changes made by one person are

immediately visible to the other.

• One approach to implementing shared files is

simply to duplicate all information about them

in both sharing directories.

11/15/2014 SDM SVV OS 37

Page 37: O svv92014

General Graph Directory

• when we add links to an existing tree-structured directory, the tree structure isdestroyed resulting in a simple graphstructure.

• If cycles are allowed to exist in the directory,we likewise want to avoid searching anycomponent twice.

• A poorly designed algorithm might result in an infinite loop continually searching through the cycle and never terminating.

11/15/2014 SDM SVV OS 38

Page 38: O svv92014

General Graph Directory

Page 39: O svv92014

• How do we guarantee no cycles?

– Allow only links to file not subdirectories

– Every time a new link is added - use a cycle

detection algorithm to determine whether it is OK

11/15/2014 SDM SVV OS 40

Page 40: O svv92014

11/15/2014 SDM SVV OS 41

Page 41: O svv92014

Allocation Methods

• An allocation method refers to how disk

blocks are allocated for files:

– Contiguous allocation

– Linked allocation

– Indexed allocation

11/15/2014 SDM SVV OS 42

Page 42: O svv92014

Contiguous Allocation

• Each file occupies a set of contiguous blocks

on the disk.

• Simple – only starting location (block #) and

length (number of blocks) are required

• Random access – possible.

• Wasteful of space (dynamic storage-allocation

problem)

• Files cannot grow

11/15/2014 SDM SVV OS 43

Page 43: O svv92014

Contiguous Allocation of Disk Space

Page 44: O svv92014

• Accessing block b + 1 after block b normallyrequires no head movement.

• When head movement is needed, it is only onetrack.

• The number of disk seeks required foraccessing contiguously allocated files isminimal.

– The amount of time that a disk drive's head takesto move to a specific location on a disk.

• Both sequential and direct access can besupported by contiguous allocation.

11/15/2014 SDM SVV OS 45

Page 45: O svv92014

Disadv

• Difficulty is finding space for a new file.

• First fit and best fit are the most common

strategies used to select a free hole from the set

of available holes.

• Algorithms suffer from the problem of

external fragmentation. Why?

• Used in

11/15/2014 SDM SVV OS 46

Page 46: O svv92014

• Older microcomputer systems used contiguous allocation on floppy disks.

• Run a repacking routine- copy to anotherfloppy or tape.

• Another problem with contiguous allocation is determining how much space is needed for a file.

• If we allocate too little space to a file – it may be extended

• If you allocate too much space -inefficient.

11/15/2014 SDM SVV OS 47

Page 47: O svv92014

Linked Allocation

• Linked allocation solves all problems ofcontiguous allocation.

• With linked allocation, each file is a linked listof disk blocks; the disk blocks may bescattered anywhere on the disk.

• The directory contains a pointer to the first and last blocks of the file.

• Each block contains a pointer to the next block

• These pointers are not made available to the user. (Game)

11/15/2014 SDM SVV OS 48

Page 48: O svv92014

11/15/2014 SDM SVV OS 49

Pointers –adr is not correct

Page 49: O svv92014

11/15/2014 SDM SVV OS 50

Page 50: O svv92014

• To create a new file, we simply create a newentry in the directory.

• This pointer is initialized to nil (the end-of-listpointer value) to signify an empty file.

• There is no external fragmentation with linkedallocation

• The size of a file does not need to be declaredwhen that file is created.

• A file can continue to grow as long as freeblocks are available.

11/15/2014 SDM SVV OS 51

Page 51: O svv92014

Dis adv

• It can be used effectively only for sequential-

access files.

• To find the ith block of a file, we must start at

the beginning of that file.

• Another disadv-the space required for the

pointers.

• If a pointer requires 4 bytes out of a 512-byte

block, then 0.78 percent of the disk used.

11/15/2014 SDM SVV OS 52

Page 52: O svv92014

• Solution - to collect blocks into multiples,

called clusters and to allocate the clusters

rather than blocks.

• Yet another problem of linked allocation is

reliability.

• If a pointer were lost or damaged.

• Partial solutions are to use doubly linked lists.

11/15/2014 SDM SVV OS 53

Page 53: O svv92014

Indexed Allocation

• Linked Allocation –Adv?

– No external fragmentation & Size declaration pblm

• Linked allocation Disadv?

– No direct Access

• IndexedNo External fragmentation & Direct

access

• All pointers brought into one location called

index block.

• Each file has its own index block.

11/15/2014 SDM SVV OS 54

Page 54: O svv92014

• How to access 3rd block of a file?

• The directory contains the address of the index

block.

11/15/2014 SDM SVV OS 55

Page 55: O svv92014

• Indexed allocation does suffer from wastedspace Pointer overhead is more.

• Ex. a file of only one or two blocks.

• If the index block is too small - it will not beable to hold enough pointers for a large file.

• Solution:

– Linked Scheme :link together several index blocks

– Multilevel index: first level index block to point to a set of second-level index blocks, which in turn point to the file blocks.

11/15/2014 SDM SVV OS 56

Page 56: O svv92014

Free-Space Management

• Disc space limited-reused.

• The system maintains a free-space list.

• To create a file -search the free-space list-

there- removed from the free-space list.

• File deleted -its disk space is added to the free-

space list.

11/15/2014 SDM SVV OS 57

Page 57: O svv92014

Bit Vector

• The free-space list is implemented as a bit map

or bit vector.

• Each block is represented by 1 bit. If the block

is free, the bit is 1.

• Blocks 2, 3,4,5, 8, 9, 10, 11, 12, 13, 17, 18, 25,

26, and 27 are free, and the rest of the blocks

are allocated.

11/15/2014 SDM SVV OS 58

Page 58: O svv92014

• The main advantage-relatively simplicity.

• Disadvantage

– Bit vectors are inefficient unless the entire vector

is kept in main memory.

– A 1.3-GB disk with 512-byte blocks would need a

bit map of over 332 KB to track its free blocks

11/15/2014 SDM SVV OS 59

Page 59: O svv92014

Linked List

• Linked Allocation?

11/15/2014 SDM SVV OS 60

Page 60: O svv92014

Linked List

• Another approach is to link together all the

free disk blocks.

• Keeping a pointer to the first free block.

• First block contains a pointer to the next free

disk block, and so on.

• Ex. keep a pointer to block 2, it contain a

pointer to block 3, which would point to block

4, which would point to block 5.

11/15/2014 SDM SVV OS 61

Page 61: O svv92014

Linked free space list on disk

11/15/2014 SDM SVV OS 62

Page 62: O svv92014

• Disadvantages

– we must read each block

• Grouping:

– A modification of the free-list approach is to store

the addresses of n-1 free blocks in the first free

block.

– The last block contains the addresses of another nfree blocks, and so on.

– Adv to compared to linked as most of the free

blocks addresses are available in one block.

11/15/2014 SDM SVV OS 63

Page 63: O svv92014

• Counting:

– WKT several contiguous blocks may be allocated

or freed simultaneously (in contiguous-allocation)

– Rather than keeping a list of n free disk addresses

keep the address of the first free block and the

number n.

11/15/2014 SDM SVV OS 64

Page 64: O svv92014

11/15/2014 SDM SVV OS 65

End of Topic

Page 65: O svv92014

ಆನಂದಾಶ್ರಮಮತ್ತು ಮಹಿಷಿ ಟ್ರಸ್ಟದಲಿ್ಲ ಎಸ್ ಡಿ ಎಮ್ ಕನನಡ ವೆೇದಿಕೆಯ ಸ್ಹಯೇಗದೆ ಂದಿಗೆಹಮ್ಮಿಕೆ ಂಡಿರತವ ಕಿರತ ಕಾಣಿಕೆ ಹಾಗ ಸ್ಂಗೇತ್ ಕಾಯಯಕರಮದಲ್ಲಿ ಧ್ವನಿ ತ್ಂಡ ನಡೆಸಿದ

ಸ್ಂಗೇತ್ ಕಾಯಯಕರಮ ಅಲಿ್ಲಯ ಜನರಮನಗೆದತು ಅವರನತನ ಖತಷಿಯಾಗಸಿತ್ತ.

11/15/2014 SDM SVV OS 66

Page 66: O svv92014

• Daughter of Pandit Mallikarjun Mansoor

11/15/2014 SDM SVV OS 67

Page 67: O svv92014

11/15/2014 SDM SVV OS 68

Page 68: O svv92014

11/15/2014 SDM SVV OS 69

Page 69: O svv92014

End of Topic

11/15/2014 SDM SVV OS 70

Page 70: O svv92014

11/15/2014 SDM SVV OS 71

Page 71: O svv92014

11/15/2014 SDM SVV OS 72

Chandrakant Kanavi

Page 72: O svv92014

11/15/2014 SDM SVV OS 73

Page 73: O svv92014

• Prof. Shakuntala

11/15/2014 SDM SVV OS 74

Page 74: O svv92014

End of Topic

11/15/2014 SDM SVV OS 75