Professional Documents
Culture Documents
1
File Read and Write Disk Layout
Read 10 bytes from a file starting at byte 2? Boot Super File descriptors
File data blocks
seek byte 2 block block (i-node in Unix)
fetch the block
Boot block
read 10 bytes Code to bootstrap the operating system
Write 10 bytes to a file starting at byte 2? Super-block defines a file system
seek byte 2 Size of the file system
Size of the file descriptor area
fetch the block Free list pointer, or pointer to bitmap
write 10 bytes in memory Location of the file descriptor of the root directory
write out the block Other meta-data such as permission and various times
Kernel keeps in main memory, and is replicated on disk too
File descriptors
Each describes a file
File data blocks
Data for the files, the largest portion on disk
5 6
2
Linked Files (Alto) File Allocation Table (FAT)
File header points to 1st Approach foo 217
block on disk File header Table of “next pointers”, indexed by block
• Instead of pointer stored with block
A block points to the next 0
Directory entry points to 1st block of file
Pros Pros
Can grow files dynamically No need to traverse list to find a block
217 619
Free list is similar to a file Cache FAT table and traverse in memory
... Cons
No external fragmentation
399 EOF
or need to move files FAT table takes lots of space for large disk
• Hard to fit in memory; so may need seeks
Cons
Pointers for all files on whole disk are interspersed
Random access: horrible null in FAT table 619 399
Even sequential access • Need full table in memory, even for one file
needs one seek per block • Solution: indexed files
Unreliable: losing a block • Keep block lists for different files together,
and in different parts of disk FAT
means losing the rest
9 10
11 12
3
Multi-Level Indexed Files (Unix) What’s in Original Unix i-node?
13 Pointers in a header Mode: file type, protection bits, setuid, setgid bits
10 direct pointers Link count: number of directory entries pointing to this
11: 1-level indirect data Uid: uid of the file owner
12: 2-level indirect
Gid: gid of the file owner
13: 3-level indirect
1
data File size
Pros & Cons ...
2
Extents Naming
Instead of using a fix- Text name
sized block, use a Block offset Need to map it to index
number of blocks
length Index (i-node number)
XFS uses 8Kbyte block
Max extent size is 2M Starting block Ask users to specify i-node number
blocks Icon
Index nodes need to have Need to map it to index or map it to text then to index
Block offset ...
Length
Starting block
Is this approach better
than the Unix i-node
approach?
15 16
4
Directory Organization Examples Mapping File Names to i-nodes
Flat (CP/M) Create/delete
All files are in one directory Create/delete a directory
Hierarchical (Unix) Open/close
/u/cos318/foo Open/close a directory for read and write
Directory is stored in a file containing (name, i-node) pairs Should this be the same or different from file open/close?
The name can be either a file or a directory Link/unlink
Hierarchical (Windows) Link/unlink a file
C:\windows\temp\foo Rename
Use the extension to indicate whether the entry is a directory Rename the directory
17 18
5
Hashing Disk I/Os to Read/Write A File
Method Disk I/Os to access a byte of /u/cos318/foo
Use a hash table to map Read the i-node and first data block of “/”
FileName to i-node Read the i-node and first data block of “u”
Space for name and Read the i-node and first data block of “cos318”
metadata is variable sized foo 1234 Read the i-node and first data block of “foo”
Create/delete will trigger bar 1235
space allocation and free Disk I/Os to write a file
Read the i-node of the directory and the directory file.
Pros
…
foobar 4567 Read or create the i-node of the file
Fast searching and relatively
simple Read or create the file itself
Write back the directory and the file
Cons
Not as efficient as trees for
very large directory (wasting Too many I/Os to traverse the directory
space for the hash table) Solution is to use Current Working Directory
21 22
23 24
6
BSD FFS (Fast File System) FFS Disk Layout
Use a larger block size: 4KB or 8KB i-nodes are grouped together
Allow large blocks to be chopped into foo A portion of the i-node array on each
cylinder
fragments
Do you ever read i-nodes without
Used for little files and pieces at the
reading any file blocks?
ends of files
Overcome rotational delays
Use bitmap instead of a free list bar
Skip sector positioning to avoid the
Try to allocate contiguously context switch delay
10% reserved disk space Read ahead: read next block right
after the first
i-node subarray
25 26
27 28