file system new
file system new
File System
Introduction:
8.1
Introduction to Operating System
8.2
Introduction to Operating System
This information may be kept for creation, last modification, and last use. These
data can be useful for protection, security, and usage monitoring.
8.1.1. File Operations:
A file is an abstract data type.
To define a file properly, user need to consider the operations that can be
performed on files.
The operating system can provide system calls to create, write, read,
reposition, delete, and truncate files.
1) Creating a File:
Two steps are necessary to create a file. First, space in the file system must
be found for the file.
Second, an entry for the new file must be made in the directory.
2) Writing a File:
To write a file, a system call must be made for specifying both the name of
the file and the information to be written to the file.
Given the name of the file, the system searches the directory to find the
file's location.
The system must keep a write pointer to the location in the file, where the
next write is to take place.
The write pointer must be updated whenever a write occurs.
3) Reading a File:
To read from a file, a system call is used that specifies the name of the file
and where (in memory) the next block of the file should be put.
Again, the directory is searched for the associated entry, and the system
needs to keep a read pointer to the location in the file, where the next read is
to take place.
Once the read has taken place, the read pointer is updated.
4) Repositioning within a File:
The directory is searched for the appropriate entry, and the current file-
position pointer is repositioned to a given value.
Repositioning within a file need not involve any actual I/O.
8.3
Introduction to Operating System
8.4
Introduction to Operating System
Sequential Access
8.5
Introduction to Operating System
Direct access is based on a disk model of a file. For direct access, the file is
viewed as a numbered sequence of block or records. A direct-access file
allows arbitrary blocks to be read or written.
There are no restrictions on the order of reading and writing for a direct
access file.
Direct access files are of great use for intermediate access to large amounts
of information.
The file operations must be modified to include the block number as a
parameter. Not all OS support both sequential and direct access for files.
Some systems allow only sequential file access; others allow only direct
access.
Some systems require that a file be defined as sequential or direct when it is
created; such a file can be accessed only in a manner consistent with its
declaration.
8.3 File Structure:
File types can be used to indicate the internal structure of the file.
1) Stream of Bytes:
A field is the basic element of data. An individual field contains a single
value.
OS considers file to be unstructured..
2) Records:
A file is a collection of similar records.
A file is a sequence of fixed length record, each with some internal structure.
Collection of bytes treated as a unit.
File is a collection of similar records. OS can optimize operation on records.
3) Tree of Records (database):
A database is a collection of related data.
A file consist of a tree of records, not necessarily all the same length.
Record can be variable length.
8.6
Introduction to Operating System
8.7
Introduction to Operating System
8.8
Introduction to Operating System
8.9
Introduction to Operating System
ATree
Advantages:
No External Fragmentation
Any free blocks can be added to a chain.
No Need to Declare Size
Improves Disk Throughput
Disadvantages :
Linked list allocation does not support direct access or random access.
In the disk block for the pointer, it needs some extra space.
In linked list allocation, we need to traverse each block.
In the disk block for the pointer, it needs some extra space.
8.10
Introduction to Operating System
8.11
Introduction to Operating System
Disadvantages :
In index allocation, pointer overhead is more.
We can lose the entire file if an index block is not correct.
It is totally a wastage to create an index for a small file.
8.12
Introduction to Operating System
3. 0000111000000110
Linked List:
Another approach is to link together all the free disk blocks, keeping a
pointer to the first free block in a special location on the disk and caching it in
memory.
This first block contains a pointer to the next free disk block, and so on.
Block 2 would contain a pointer to block 3, which would point to block 4,
which would point to block 5, which would point to block 8, and so on.
Usually, the operating system simply needs afree block so that it can
allocate that block to a file, so thefirst block in the free list is used.
Example: 0000111000000110
8.13
Introduction to Operating System
B) Grouping:
A modification of the free-list approach is to store the addresses of n free
blocks in the first free block.
The first n-1of these blocks are actually free. The importance of this
implementation is that the addresses of a large number of free blocks can be
found quickly, unlike in the standard linked-list approach.
C) Counting:
Several contiguous blocks may be allocated or freed simultaneously,
particularly when the space is allocated with the contiguous allocation
algorithm or through clustering.
In a list of n free disk addresses, user can keep the address of the first free
block and the number n of free contiguous blocks that follow the first block.
Each entry in the free-space list then consists of a disk address and a count.
Although each entry requires more space than would a simple disk address,
the overall list will be shorter, as long as count is generally greater than 1.
Review Questions
MCQ 1Marks
1) _____ is a unique tag, usually a number identifies the file within the file
system.
a)File identifier
b)File name
c)File type
d) None of the mentioned
8.14
Introduction to Operating System
8.15
Introduction to Operating System
c) Indexed Allocation
d) All of the above
Q. 1. What is the concept of file? Explain in detail the operations to be performed with
a file and types of access on a file.
Q. 2. Explain in detail the following access methods:
a) Sequential Access.
b) Direct Access.
Q. 3. Explain in detail the structure of a file and its attributes.
Q. 4. What are the advantages and disadvantages of contiguous allocation method?
Explain in detail the process of contiguous allocation method.
Q. 5. Explain the following free space management tools:
a) Bit Vector
b) Linked List.
c) Grouping.
d) Counting.
Q. 6. Explain in detail the process of indexed allocation method. What are the
advantages and disadvantages of the indexed allocation method?
Q. 7. Write short notes on the following:
a) File Attributes.
b) File Types.
c) Advantages and Disadvantages of Linked Allocation.
d) Internal File Structure.
e) Process of Linked Allocation Method.
8.16