Concept of File Management
Original Scanned PDF – View Notes
File
- A file is named collection of related information that recorded on secondary storage such as magnetic disk, magnetic tape and optional disk.
- In general, a file is a sequence of bits, bytes, lines or records whose meaning is defined by file creator or user.
Attributes of File
Following are some file attributes:
1. Name
Only information which is in human readable form.
2. Identifier
File is identified by a unique tag (number) within file system.
3. Type
It is needed for system that support different types of files.
4. Location
Pointer to file location on device.
5. Size
Current size of file.
6. Protection
Controls and assigns the power of reading, writting, executing.
7. Time, Data and User Identification
This is the data for protection, security and usage monitoring.
Operation on File
The OS must do to perform basic file operations given below.
- Creating file
- Writing file
- Reading file
- Repositioning within a file
- Deleting a file
- Protection
- Truncating file
1. Creating File
Allocate space and then make an entry in the directory.
2. Write
- Required name of file and the information to be written.
- Search the directory to find location of file.
- Keep a write-pointer to the location in the file.
- Update the pointer after each write.
3. Read
- Requires name of file and information to be read.
- Search the directory to find location of file.
- Keep a read-pointer to the location in the file.
- Update the pointer after each read.
4. Repositioning Within a File
Change the value of the file-position pointer.
5. Delete
Deallocate the space and remove entry.
6. Protection
Changing access-control information such as who can read, write, execute and so on.
7. Truncate
Change the allocation space to zero and deallocate file space.
File Allocation
- File allocation is the process of storing files in the disk blocks.
- File allocation method defines how the files are stored in the disk.
- There are three main disk space or file allocation methods.
- Contiguous Allocation
- Indexed Allocation
- Linked Allocation
1. Contiguous Allocation
- In this scheme, each file occupies a continuous set of blocks on the disk.
- The directory entry for a file with continuous allocation contains:
- Address of starting blocks.
- Length of allocated portion.
Example: If a file requires n blocks and block b is starting location then block assigned to the file will be:
b, b+1, b+2 ... b+n-1
Directory
| File | Start | Length |
|---|---|---|
| count | 0 | 2 |
| trt | 14 | 3 |
| 7 | 3 |
Advantage
- Both random and sequential access are supported.
- Extremely fast to access.
Disadvantage
- Suffers from both internal and external fragmentation.
- Large size file in different to allocate.
2. Linked List Allocation
- In this scheme, each file is a linked list of disk blocks which need not be contiguous.
- Disk blocks is scattered anywhere on the disk.
- The directory entry contains a pointer to the starting and the ending file block.
- Each block contains pointer to the next block occupied by file.
Advantage
- Very flexible in terms of size.
- Does not suffer from external fragmentation.
Disadvantage
- Large no of seeks are needed to access blocks causes slower access.
- Does not support random or direct access.
- Pointer adds extra overhead.
3. Indexed Allocation
- In this allocation, a special blocks known as the index block contains the pointer to all blocks occupied by a file.
- Each file has its own index block.
- The ith entry in the index block contains the disk address of the ith file block.
- The directory entry contains the address of the index block.
Advantage
- Support direct access to the blocks occupied by file.
- Overcomes the problem of external fragmentation.
Disadvantage
- Pointer overload is greater.
- For small files it is inefficient in terms of memory utilization.
Discussion
Share a helpful question, idea, or explanation with other students.