Module V
FILE SYSTEM
OBCA104
Presented by
Latharani T R
Assistant Professor
Dept. of Computer Science and Engineering
Jain Institute of Technology
Davanagere.
1
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
Introduction
File Concepts
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
2
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
File Types
Four types of file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
3
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
4
2) Source file:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
5
3) Object file:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
6
4) Executable file:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
7
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
8
File Attributes
1) Name: The only information kept in human-readable form.
2) Identifier: It is a unique number which identifies the file within file-system.
It is in non-human-readable form.
3) Type: It is used to identify different types of files.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
9
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
10
Time, date, & user identification
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
11
File Operations
1) Creating a file
i) Find the space in the file-system for the file.
ii) An entry for the new file is made in the directory.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
12
2) Writing a file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
13
3) Reading a file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
14
4) Repositioning within a file
5) Deleting a file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
15
6) Truncating a file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
16
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
17
2) System-wide Table
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
18
1) File-pointer
2) File-open Count
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
19
3) Disk Location of the File
4) Access Rights
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
20
File Types
1) Name and
2) Extension (.doc, .txt, .exe etc.)
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
21
File Structure
• Too few structures make programming inconvenient.
• Too many structures make programmer confusion.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
22
Internal File Structure
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
23
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
24
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
25
Access Methods �
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
26
Sequential Access
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
27
File-operations
1) Read next
2) Write next
3) Rewind
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
28
Sequential-access file
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
29
Direct Access (Random/Relative Access)
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
30
Simulation of sequential access on a direct-access file.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
31
�
Other Access Methods
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
32
Example of index and relative files
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
33
Problem: With large files, the index-file itself may become too large to be kept in memory. Solution: Create an index for the index-file.
Directory Structure�
Storage Structure
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
34
A typical file-system organization��
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
35
Directory Overview
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
36
Single-Level Directory
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
37
Disadvantages (Limitations):
1) Naming problem: All files must have unique names.
2) Grouping problem: Difficult to remember names of all files, as number of files increases.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
38
Two-Level Directory
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
39
Disadvantage
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
40
Two-level directory structure
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
41
Tree-Structured Directories
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
42
Tree-structured directory structure
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
43
Advantage:
1) Users can be allowed to access the files of other users.
Disadvantages:
1) A path to a file can be longer than a path in a two-level directory.
2) Prohibits the sharing of files (or directories).
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
44
Acyclic-Graph Directories�
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
45
Acyclic-graph directory structure
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
46
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
47
Two problems:
1) A file may have multiple absolute path-names.
2) Deletion may leave dangling-pointers to the non-existent file.
Solution to deletion problem:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
48
General Graph Directory
Problem:
Solution:
Limit the no. of directories accessed in a search.
Problem:
With cycles, the reference-count may be non-zero even when it is no longer possible to refer to a directory (or file).
Solution: Garbage-collection scheme can be used to determine when the last reference has been deleted.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
49
General Graph Directory
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
50
1) First pass
2) A second pass
Collects everything that is not marked onto a list of free-space
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
51
File System Structure
1) A disk can be rewritten in place.
2) A disk can access directly any block of information.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
52
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
53
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
54
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
55
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
56
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
57
Advantages of layered structure:
1) Duplication of code is minimized.
2) I/O control can be used by multiple file-systems.
Allocation Methods
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
58
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
59
Contiguous allocation
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
60
Contiguous allocation of disk space
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
61
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
62
Linked allocation
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
63
Linked allocation of disk space.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
64
1) A write to the file causes a free block to be found,then written and linked to the eof (end of file).
2) A read to the file causes moving the pointers from block to block.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
65
Advantages
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
66
Disadvantages:
1) Can be used effectively only for sequential-access files.
2) Space required for the pointers.
3) Reliability: Problem occurs if a pointer is lost( or damaged).
i) Use doubly linked-lists.
ii) Store file name and relative block-number in each block.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
67
FAT (File Allocation Table)
Advantages:
Disadvantage:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
68
Indexed Allocation
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
69
Indexed allocation of disk space
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
70
Disadvantages:
1) Suffer from wasted space
2) The pointer overhead of the index block is generally greater than the pointer overhead of linked allocation.
3) Suffer from performance problems.
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
71
Free-Space Management
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
72
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
73
Methods
The OS uses various techniques to manage free space and optimize the use of storage devices.
Bit Vector
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
74
0 0 0
0 1 1
1 0 0
0 0 0
0 1 1
0
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
75
BIT VECTOR
Advantages
Disadvantages
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
76
Linked List
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
77
Linked List
Disadvantage
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
78
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
79
Grouping
Advantage:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
80
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
81
Counting
Advantage:
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
82
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
83
5
2
14
1
Counting list entry
Latharani T R, Assistant Professor, Dept. of CS&E, JIT, Davanagere
84