mod 256

advertisement
Block Diagram of the System Kernel
user programs
libraries
User level
Kernel level
system call interface
inter process
com
file sub system
buffer
cache
character block
device drivers
process
control
sub
system
scheduler
memory
management
hardware control
Kernel level
Hardware level
hardware
d:\533567807.doc
1
File system
Provides abstraction from physical device to
a logical model
/
Logical model:
files, directories
file system
mapping
system
calls
device
drivers
logical device
physical
hardware
disk
sectors
read/write
head
d:\533567807.doc
tracks
2
Access Methods
Some o/s support a variety of access
methods, to suit application
Sequential access
 data accessed in an ordered sequence
 useful for linker, compiler, editor
Direct/random access
 data records accessed in a random order
 useful for databases
File systems - logically structured in
hierarchies of directories
Directory - a list of file entries
File entries
 different for different access method
 include file info, eg permissions
d:\533567807.doc
3
Contiguous
allocation
file f1
0 1 2 3 4
file f2
5 6 7 8 9
Entry has start block and size:
ID
start size
f1
0
2
f2
4
4
+ easy access & caching
- free space becomes fragmented
- where to place a new file ?
Could manage free space by allocating it to
files of known length
Used in writable CDROMs and DVDs
d:\533567807.doc
4
Linked
allocation
Directory
0 1 2 3 4
file f1
1
5 6 7 8 9
file f2
4
10 11 12 13 14
Entry points to first data block.
Data block points to next block
End data block points to ‘eof’
next
data
+ no fragmentation of free space
- access is basically sequential
- more pointers so more lost pointers
- space required for pointers
- must follow all links to access final block
- much more disk head movement
d:\533567807.doc
5
Indexed allocation 1
File Allocation Table
Block Points
# to
0
Directory
1 3
file f1
1
2
3 eof
file f2
4
4 6
5
6 12
7
0 1 2 3 4
8
9
5 6 7 8 9
10 eof
11
10 11 12 13 14
12 10
FAT entries point to: next entry or ‘eof’
data block
+ no fragmentation of free space
+ access can be in any order
+ in-memory FAT faster to search
+ less pointers so less lost pointers
+ less disk head movement
- in-memory FAT can be huge
d:\533567807.doc
6
Indexed
allocation 2
Directory
file f1
5
0 1 2 3 4
file f2
8
5 6 7 8 9
Block 8
1 4
2 6
3 12
4 10
10 11 12 13 14
Entry points to an index block
Index block points to data blocks
+ no fragmentation of free space
+ access can be in any order
- space required for index of pointers
- more pointers so more lost pointers
- more disk head movement
d:\533567807.doc
7
Inode=index node
Inode has pointers to
data blocks
direct 0
index blocks
direct 1
direct 2
direct 3
direct 4
direct 5
direct 6
direct 7
direct 8
direct 9
single
index
indirect
blocks
double
indirect
triple
indirect
data
blocks
:
triple double single
indirect index blocks
d:\533567807.doc
8
Maximum Addressable File Size
For a block size of 1024 bytes (1 K byte)
and a pointer size of 4 bytes (32 bits adres)
gives 1024/4 = 256 pointers in each index
(=pointer) block
10 direct pointers
which point to
10240 = 10 K bytes
1 single indirect pointer block has
256 pointers
which point to
262144 = 256 K bytes
1 double indirect pointer block has
256 single indirect pointers
which each point to 256 indirect pointer
blocks, which point to [256 * 256 K bytes]
67108864 = 64 M bytes
1 triple indirect pointer block has
256 double indirect pointers, which each
point to 256 indirect pointer blocks, which
point to [256 * 64 M bytes]
17179869184 = 16 G bytes
17247250432 bytes = ~16 G bytes
d:\533567807.doc
9
For a block size of 1024 bytes (1 K byte)
and a pointer size of 4 bytes (32 bits adres)
inode
10 direct
pointers
1 single
indirect
block
1 double
indirect
block
1 triple
indirect
block
data blocks running total
10240
= 10 K bytes
10240
262144
= 256 K bytes
272384
67108864
= 64 M bytes
67381248
17179869184
= 16 G bytes
17247250432
However, with 32 bit addressing, max
addressable file is 232 = 4 G bytes
d:\533567807.doc
10
Finding File Data
1.calculate logical block & byte offset
2.find block pointer
3.read block
eg 1: find byte 9000, for a block size of
1024 bytes
9000 < 10240, so is addressable by direct
pointers
file block = 9000 DIV 1024 = 8
offset
= 9000 MOD 1024 =808
ie direct pointer 8 points to a block (block
367 in the fig) whose 808th byte is byte
9000
d:\533567807.doc
11
0 4096
228
45423
0
0
11111
0
101
8 367
0
428
0
808
1023
367
data
block
0
331
9156
75
824
255
9156
double
indirect
d:\533567807.doc
3333
816
3333
331
data
block
single
indirect
12
eg 2: find byte 350000, for a block size of
1024 bytes
file block = 350000 DIV 1024 = 341
offset
= 350000 MOD 1024 = 816
272384 < 350000 > 67381248 bytes, or
266 < 341 < 256*256 + (256+10) blocks,
so need double indirect blocks
341-266=75, ie pointed at by the 75th block
of the 256 * 256 blocks addressable via
double indirect blocks (IBs)
75 DIV 256 = 0, double IB 0 (9156)
75 MOD 256 = 75, single IB 75 (331)
ie 75th single indirect block of 0th double
indirect block, points to data block 3333
Block 3333 has byte 350000 at offset 816
Check
350000 - 272384 = 77616
file block = 77616 DIV
1024 = 75
offset
= 77616 MOD 1024 =816
d:\533567807.doc
13
Download