Lecture-Files and Directories
Lecture-Files and Directories
BCS303
• The program in the boot block loads the operating system contained in that partition.
• For uniformity, every partition starts with a boot block, even if it does not contain a bootable operating system.
• The layout of a disk partition varies a lot from file system to file system.
• Superblock contains all the key parameters about the file system and is read into memory when the computer is booted
or the file system is first touched.
• Typical information in the superblock includes a
Magic number to identify the file-system type,
The number of blocks in the file system, and
Other key administrative information.
FILE-SYSTEM IMPLEMENTATION
Users are concerned with how
Files are named,
What operations are allowed on them,
What the directory tree looks like, and similar interface issues.
Implementers are interested in how
Files and directories are stored,
How disk space is managed, and
How to make everything work efficiently and reliably.
• Most important issue in implementing file storage is keeping track of which disk blocks go with
which file.
Various methods are used in different operating systems. some methods are discussed are as follows:
1. Contiguous Allocation
2. Linked-List Allocation
3. Linked-List Allocation Using a Table in Memory
4. I-nodes
Contiguous Allocation
• The simplest allocation scheme is to store each file as a contiguous run of disk blocks.
• On a disk with 1-KB blocks, a 50-KB file would be allocated 50 consecutive blocks and with 2-KB
blocks, it would be allocated 25 consecutive blocks.
• Fig. shows an example of contiguous storage allocation.
Contiguous Allocation
Contiguous disk-space allocation has two significant advantages.
1. It is simple to implement because keeping track of where a file’s blocks are, is
reduced to remembering two numbers:
• The disk address of the first block and
• The number of blocks in the file.
2. Read performance is excellent because the entire file can be read from the disk in
a single operation.
• Only one seek is needed (to the first block).
• After that, no more seeks or rotational delays are needed, so data come in at the
full bandwidth of the disk.
Contiguous Allocation
Cont..
Contiguous allocation also has a very serious drawback:
Over the course of time, the disk becomes fragmented as shown in Fig.
Initially, fragmentation won’t be a problem, but as the disk fills, the holes are to be used which is going to
be time consuming in keep tracking of the size of the hole
Fig. The state of the disk after files D and F have been removed.
Linked-List Allocation
The second method for storing files is to keep each one as a linked list of disk blocks, as shown in Fig.
Linked-List Allocation
Cont…
The first word of each block is used as a pointer to the next one.
The rest of the block is for data.
Every disk block can be used in this method.
No space is lost to disk fragmentation
It is sufficient for the directory entry to merely store the disk address of the
first block.
The rest can be found starting there.
Drawback is random access is extremely slow, and also
Amount of data storage in a block is no longer a power of two because the
pointer takes up a few bytes
Linked-List Allocation Using a Table in
Memory
Disadvantages of the linked-list allocation can be eliminated by taking
the pointer word from each disk block and putting it in a table in
memory
Fig. shows what the table looks like for the example of linked list Fig.
File A uses disk blocks 4, 7, 2, 10, and 12, in that order, and file B uses disk
blocks 6, 3, 11, and 14, in that order.
Using the table of Fig. we can start with block 4 and follow the chain all
the way to the end.
The same can be done starting with block 6.
Both chains are terminated with a special marker (e.g., −1) that is not a
valid block number.
Such a table in main memory is called a FAT (File Allocation Table).
Given the i-node, it is then possible to find all the blocks of the
file.
The big advantage of this scheme over linked files using an in-
memory table is that the i-node need be in memory only when the
corresponding file is open.
If each i-node occupies n bytes and a maximum of k files may be
open at once, the total memory occupied by the array holding the
i-nodes for the open files is only kn bytes
Only this much space need be reserved in advance.