Download presentation
Presentation is loading. Please wait.
Published byLauren Freeman Modified over 6 years ago
1
File Management Computer can store information on storage media such as magnetic disks, tape and so on. The physical storage is converted into logical storage by OS. The logical storage unit is said to be a “File”. Files are mapped by the operating system onto physical devices. A File is a collection of similar records. A record is a collection of related fields that can be treated as a unit by some application program. A field is the some basic element of data. Any individual field contains single value.
2
File Attributes Name—human readable form
Identifier –non human readable name (unique identifier) Type—type supported Location—pointer to the device and to the location of the file on that device Size—number of bytes Protection—read, write and execute permissions Time & Date—creation, last modification and last use info User Identification—name of logged in user The information about file is stored in secondary memory mainly called the directory entry.
3
File Operations Creating a file—allocate free space on disk and make entry in the directory Writing to File—system call to write name of the file and to write the data Reading from file—keep the read pointer to the location of the file Repositioning with in a file—search the directory for current position and reposition the file pointer to new position Deleting files—release all file space and erase directory entry Truncating files—erase the contents of the file but keep the attributes
4
File Types
5
File Management System
A file management system (FMS) is a collection of system software programs that provides services to the users. It’s objectives are: To provide the I/O support for multi users. To provide a standardize set of I/O interface routines. Storage of data To optimize the performance To provide I/O support for a variety of storage device types. To guarantee that the data in the file are valid.
6
File System Architecture
User Program Sequential Indexed Sequential Indexed Hashed Logical I/O Basic I/O supervisor Basic File System Disk device driver Tape device driver
7
File System Architecture
At the lowest level, device driver directly communicate with peripheral devices or controllers or channels. A device driver is responsible for starting I/O operations on a device and processing the completion of I/O request. The next level is the “basic file system”. It is the interface with the environment outside of the computer system. The “Basic I/O supervisor” is responsible for all I/O initiation and termination. “Logical I/O” enables users and applications to access records.
8
File Accessing Methods
Files stores information, this information must be accessed and read in to computer memory. There are so many ways that the information in the file can be accessed. Sequential Access Direct Access Indexed sequential
9
Sequential File Access
This method is the simplest of all methods. Information in the file is processed in order, one record after another. Example: editors. compilers For example, a file consisting of 100 records, the current position of read/write head is 45th record. Suppose we want to read 75th record then it access sequentially from 45, 46,47………73,74,75. So the read/write head traverse all the records between 45 to 75. Sequential files are typically used in batch application and payroll applications. Current Position Target Position end Beginning
10
Direct Access Direct access is called relative access.
In this method, records can read/write randomly without any order. The direct access method is based on disk model of a file, because disks allow random access to any file block. A direct access file allows arbitrary blocks to be read or written. For example, a disk consisting of 256 blocks, the current position of read/write head is at 95th block. The block to be read or write is 250th block. Then we can access the 250th block directly without any restrictions. Another example for direct access is CD having 10 songs, at present we are listening the song no:3, suppose we want to listen the song no:9 then we can move from 3 to 9 without any restrictions.
11
Indexed Sequential File
The main disadvantage in sequential file is that it takes more time to access a record. We can overcome this problem by using indexed sequential file. Records are organized in sequence based on a key field. For example, a file is consisting of 60,000 records, the master index divide the total records in to 6 blocks, each block consisting of a pointer to secondary index. The secondary index divide the 10,000 records into 10 indexes. Each index consisting of a pointer to its original location. Each record in the index file consisting of 2 fields. A key field and a pointer field. Suppose we want to access the 55,550th record, this pointer points to the 6th index in the secondary index. This index points to the original location of the record from 55,000 to 56,000.
12
Indexed Sequential File
0-1000 . ,000 0-10,000 . 10,000-20,000 20,000-30,000 30,000-40,000 40,000-50,000 50,000-60,000 . ,000
13
File Directories The directory contains information about the files including attributes, locations and ownership. Sometimes the directories consisting of subdirectories also. The directory is itself a file, owned by the operating system and accessible by various file management routines. Sometimes the file system consisting of millions of files, at that situation it is very hard to manage the files. To manage these files grouped these files and load one group in to one partition. Each partition is called a directory. The directory can be viewed as a symbol table that translate filenames in to their directory entries. A directory structure provides a mechanism for organizing many files in the system.
14
Operations on the file directories
Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system
15
Single Level Directory
It is simplest of all directory structures. In this directory system having only one directory, it consisting of the all files. Sometimes it is said to be “Root Directory”. Advantage: Simple and Locate files quickly Issue: different users may accidentally use the same names for their files.
16
Two Level Directory The problem in single level directory is different users may be accidentally use the same names for their files. To avoid this problem, each user need a private directory. In this way, name chosen by one user don’t interfere with names chosen by different user and there is no problem caused by the same occurring in two or more directories.
17
Hierarchical structure directory
The two level directory eliminates name conflicts among users but it is not satisfactory for users with a large number of files. To avoid this, creates the subdirectory and load the same type of files in to the subdirectory. So, in this method each can have as many directories are needed. This directory structure looks like tree, that’s why it is also called tree level directory structure.
18
Hierarchical structure directory
If a reference is made to the file the current directory is searched. If a file is needed that is not in the current directory, then the user usually must either specify the path name or change the current directory To change directories system calls are provided which takes name as a parameter. Two types of path : absolute and relative An absolute path 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.
19
Acyclic-Graph directory
A shared directory or file will exist in the file system in two(or more) places at once. An acyclic graph—that is a graph with no cycles—allows directories to share sub directories and files. With a shared file, only one actual file exists, so any changes made by one person are immediately visible to the other.
20
Directory Implementation—Linear list
Use linear list of names with pointers to the data blocks. To create a new file, we must first search the directory to be sure that no existing file has the same name. Then, we add a new entry at the end of the directory. To delete a file, we search the directory for the named file and then release the space allocated to it. To reuse the directory, we can attach it to the list of free directory entries. Disadvantages : It requires linear search, users will notice the slow speed while the pointer searches the whole list.
21
Directory Implementation—Hash Table
Here the linear list store the directory entries but the hash table take the value computed from the file name and returns the pointer to the file name in the linear list. It decreases directory search time. Collisions – situations where two file names hash to the same location
22
File Allocation Methods
Contagious allocation Linked Allocation Grouped allocation (or) indexed allocation
23
Contagious Method In this scheme, each file occupies a set of contagious blocks on the disk. This method is best suited for sequential files. The main problem in this is it is difficult to find the contagious free blocks in the disk. Another problem is external fragmentation, it means some free blocks could happen between two files.
24
Contagious Allocation
25
Linked Allocation Method
Very easy to locate files because allocation is on an individual block basis. Each block contains a pointer to the next free block in the chain. A file allocation table consisting of a single entry for each file. Using this method, any free block can be added to a chain very easily. There is a link between one block to another block. So it is called linked allocation. Advantages: Avoid the external fragmentation Suited for sequential files. Disadvantages: The pointer itself occupies some memory with the block. It takes much accessing time.
26
Linked Allocation
27
Indexed Allocation Brings all pointers together into the index block.
Logical view. index table
28
Indexed Allocation Method
In this method, the file allocation table contains a single entry for each file. The entry consisting of one index block, the block having the pointers to the other blocks which were occupied by the particular file. Advantages: Indexed allocation supports both sequential and direct access files, that’s why it is the most popular method. The file indexes are not physically stored as part of the file allocation table. Whenever the file size increases, we can easily add some more blocks to the index. No External Fragmentation.
29
Indexed Allocation
30
Free-Space Management
Since the disk space is limited, we need to reuse the space from the deleted files for new files. To keep the track of free disk space, the system maintains a free-space list. The free-space list records all free disk blocks— those not allocated to some file or directory. To create a file, we search the free-space list for the required amount of space and allocate that space to the new file. This space is then removed from the free-space list. When a file is deleted, its disk space is added to the free-space list.
31
Free-Space Management
Bit vector (n blocks) 1 2 n-1 … 0 block[i] free 1 block[i] occupied bit[i] = Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit
32
Free-Space Management (Cont.)
Bit map requires extra space. Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32K bytes) Easy to get contiguous files Linked list (free list) Cannot get contiguous space easily No waste of space Grouping Counting
33
Free-Space Management (Cont.)
Need to protect: Pointer to free list Bit map Must be kept on disk Copy in memory and disk may differ. Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk. Solution: Set bit[i] = 1 in disk. Allocate block[i] Set bit[i] = 1 in memory
34
Linked Free Space List on Disk
35
Record Blocking For I/O to be performed, records must be organized as blocks. Blocking can be done by 3 ways: Fixed Blocking Variable Length spanned blocking Variable length un spanned blocking
36
Fixed Blocking In this method, records length are fixed.
The prescribed number of records are stored in a block. For example, the block capacity is 100 records, but the number of records in the block is 90, then wasted space (100-90=10 records area) is called internal fragmentation. R2 R3 R4 R5 Track Gaps due to the hardware design Internal Fragmentation Internal Fragmentation
37
Variable length spanned Blocking
In this method, records sizes are not same, variable length records are packed into blocks with no unused space. So, some records may divide into two blocks, at this type of situation a pointer is passed from the block to another block. Block 1 Block 2 R1 R2 R3 R4 R5 R6 Gaps due to hardware design
38
Variable length Unspanned Blocking
In this method, records are variable length, but the records are not spanned between blocks. In this method, wasted area is serious problem, because of the inability to use the remainder of a block if the next record is larger than the remaining unused space. Gaps due to hardware design R1 R2 R3 R4 R5
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.