Post on 21-Jan-2016
Fall 2000 M.B. Ibáñez
Lecture 24File-System III
File System Implementation
Fall 2000 M.B. Ibáñez
Secondary Storage Management
• Space must be allocated to files
• Must keep track of the space available for allocation
• Space is allocated as one or more contiguous units or portions
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
Preallocation
• Need the maximum size for the file at the time of creation
• Difficult to reliably estimate the maximum potential size of the file
• Tend to overestimated file size so as not to run out of space
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
Portion Size
• Contiguity of space increases performance
• Large number of small portions increases the size of tables needed
• Fixed-size simplifies the reallocation of space
• Variable-size minimizes waste of unused storage
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
Methods of File Allocation
• Contiguous allocation– single set of blocks is allocated to a file at the
time of creation– only a single entry in the file allocation table
• starting block and length of the file
• Fragmentation will occur• Will become difficult to find contiguous
blocks of sufficient lengthFrom Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Contiguous File Allocation
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
File Allocation Table
File Name Start Block Length
FileAFileBFileCFileDFileE
2 39 5
18 830 226 3
FileA
FileB
FileC
FileE
FileD
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
Methods of File Allocation
• Chained allocation– allocation on basis of individual block– each block contains a pointer to the next block in the chain– only single entry in the file allocation table
• starting block and length of file
• No fragmentation
• Any free block can be added to the chain
• No accommodation of the principle of localityFrom Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Chained File Allocation
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
File Allocation Table
File Name Start Block Length
... ... ...
......FileB 5
...1
FileB
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
Methods of File Allocation
• Indexed allocation– file allocation table contains a separate one-
level index for each file– the index has one entry for each portion
allocated to the file– the file allocation table contains block number
for the index
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Indexed Allocation with Block Portions
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
File Allocation Table
File Name Index Block
...
...
...
...FileB 24
FileB
1831428
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Indexed Allocation - Var Length Portions
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
File Allocation Table
File Name Index Block
...
...
...
...FileC 24
Start Block Length
12814
341
FileB
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
UNIX File Management
• Files are streams of bytes
• Types of files– ordinary - contents entered by user or program– directory - contains list of file names and
pointers to inodes (index nodes)– special - used to access peripheral devices– named - named pipes
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000 M.B. Ibáñez
UNIX (4K bytes per block)
From Operating System Concepts Silbershatz & Galvin
Fall 2000 M.B. Ibáñez
Free-Space Management• Bit vector (n blocks)
• Block number calculation
…
0 1 2 n-1
bit[i] = 0 block[i] free
1 block[i] occupied
(number of bits per word) *(number of 0-value words) +offset of first 1 bit
From Operating System Concepts Silbershatz & Galvin
Fall 2000 M.B. Ibáñez
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
• CountingFrom Operating System Concepts Silbershatz & Galvin
Fall 2000 M.B. Ibáñez
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 memoryFrom Operating System Concepts Silbershatz & Galvin
Fall 2000 M.B. Ibáñez
Directory Implementation
• Linear list of file names with pointer to the data blocks.– simple to program
– time-consuming to execute
• Hash Table – linear list with hash data structure.– decreases directory search time
– collisions – situations where two file names hash to the same location
– fixed size From Operating System Concepts Silbershatz & Galvin