Upload
shivashekharayya-viraktamath
View
46
Download
0
Tags:
Embed Size (px)
Citation preview
Chapter 9: File-System Interface
11/15/2014 SDM SVV OS 1
Mr. S. V. Viraktamath
Dept of E&CE,
SDMCT, Dharwad
11/15/2014 SDM SVV OS 2
Chapter 10: File-System Interface
• File Concept
• Access Methods
• Directory Structure
• File-System Mounting
• File Sharing
• Protection
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
• File?
• Directories?
• Partitions?
• In this topic various aspects of files and the
major directory structures.
11/15/2014 SDM SVV OS 6
• 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
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
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
• 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
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
Snapshot
11/15/2014 SDM SVV OS 12
Snapshot of directory
11/15/2014 SDM SVV OS 13
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
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
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
• 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
Common file types
11/15/2014 SDM SVV OS 18
• File names
– Operatingsystem1
– ↓↨♥♣•◘¶☻▬↨
11/15/2014 SDM SVV OS 19
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
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
Sequential-access file.
• Sequential access is based on a tape model of a
file.
11/15/2014 SDM SVV OS 22
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
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
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
A typical file-system organization
11/15/2014 SDM SVV OS 26
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
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
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
• 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
Tree-Structured Directories
11/15/2014 SDM SVV OS 31
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
• 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
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
11/15/2014 SDM SVV OS 35
• 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
• 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
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
General Graph Directory
• 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
11/15/2014 SDM SVV OS 41
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
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
Contiguous Allocation of Disk Space
• 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
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
• 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
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
11/15/2014 SDM SVV OS 49
Pointers –adr is not correct
11/15/2014 SDM SVV OS 50
• 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
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
• 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
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
• How to access 3rd block of a file?
• The directory contains the address of the index
block.
•
11/15/2014 SDM SVV OS 55
• 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
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
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
• 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
Linked List
• Linked Allocation?
11/15/2014 SDM SVV OS 60
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
Linked free space list on disk
11/15/2014 SDM SVV OS 62
• 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
• 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
11/15/2014 SDM SVV OS 65
End of Topic
ಆನಂದಾಶ್ರಮಮತ್ತು ಮಹಿಷಿ ಟ್ರಸ್ಟದಲಿ್ಲ ಎಸ್ ಡಿ ಎಮ್ ಕನನಡ ವೆೇದಿಕೆಯ ಸ್ಹಯೇಗದೆ ಂದಿಗೆಹಮ್ಮಿಕೆ ಂಡಿರತವ ಕಿರತ ಕಾಣಿಕೆ ಹಾಗ ಸ್ಂಗೇತ್ ಕಾಯಯಕರಮದಲ್ಲಿ ಧ್ವನಿ ತ್ಂಡ ನಡೆಸಿದ
ಸ್ಂಗೇತ್ ಕಾಯಯಕರಮ ಅಲಿ್ಲಯ ಜನರಮನಗೆದತು ಅವರನತನ ಖತಷಿಯಾಗಸಿತ್ತ.
11/15/2014 SDM SVV OS 66
• Daughter of Pandit Mallikarjun Mansoor
11/15/2014 SDM SVV OS 67
11/15/2014 SDM SVV OS 68
11/15/2014 SDM SVV OS 69
End of Topic
11/15/2014 SDM SVV OS 70
11/15/2014 SDM SVV OS 71
11/15/2014 SDM SVV OS 72
Chandrakant Kanavi
11/15/2014 SDM SVV OS 73
• Prof. Shakuntala
11/15/2014 SDM SVV OS 74
End of Topic
11/15/2014 SDM SVV OS 75