File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
-
Upload
percival-ferguson -
Category
Documents
-
view
213 -
download
0
Transcript of File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
File Systems
2
What is a file?
• A repository for data
• Is long lasting (until explicitly deleted).
3
Why not just an address space?
• You may want data to persist longer than a process
• You may want data that is larger than a virtual address space
• Easier to share the data across processes.
4
Two aspects to consider …
• User’s view– Naming, type, structure, access,
attributes, operations, …
• System implementation
5
Naming
• Typically x.y
• x is supposed to give some clue about contents
• y is supposed to be the nature of the file.
6
Structure
• Byte stream
• Sequence of Records/Blocks
• Indexed Records
7
Type
• Regular files (containing data)
• Directories
• Character special files (access a character at a time)– To access serial communication devices (e.g.,
modems)
• Block special files (access a block at a time)– To access block devices (e.g., disk drives, CDs)
8
Access
• Sequential
• Random
9
Attributes
• protection, creator, owner, creation time, access time, current size, max size, record length, lock flags, ...
10
File Operations
• Create, Delete, Open, Close, Read, Write, Append, Seek, Get attributes, Set attributes, Rename
11
Directory
• A way of organizing files.
• Each directory entry has:– File/directory name– A way (pointer) to get to the data
blocks of that file/directory
12
• Flat/Single-Level Directory
• Hierarchical/Tree-Structured Directory
13
Directories
• File names: relative vs. absolute
• Directory Operations: Create: Delete directory Open Dir Close Dir Read Dir Rename Link (allow a file to appear in more than 1
directory) Unlink
14
File System Implementation
• View the disk as a logical sequence of blocks (typically 512 bytes)
• A block is the smallest unit of allocation.
• Issues:– How do you assign the blocks to files?– Given a file, how do you find its
blocks?
15
Contiguous Allocation
• Allocate a sequence of contiguous blocks to a file.
• Advantages:– Need to remember only starting location
to access any block– Good performance when reading
successive blocks on disk
• Disadvantages:– File size has to be known a priori.– External fragmentation
16
Linked List Allocation• Keep a pointer to first block of a
file. • The first few bytes of each block
point to the next block of this file.• Advantages: No external
fragmentation• Disadvantages: Random access is
slow!
File 1 File 2
17
Linked List Allocn. Using an Index (e.g. DOS)
• In the prev. scheme, we needed to go to disk to chase pointers.
• Can remove the pointers from the blocks, and maintain them separately.– Could be made to fit in memory
• Allocation is still done using linked list, but pointer chasing done in memory
18
File 1 File 2
Disk Blocks
File-Allocation Table (FAT)
19
Indexed Allocation(e.g. UNIX)
• For each file, you directly have a pointers to all its blocks.
• However, the number of pointers for a file can itself become large.
• UNIX uses i-nodes.• An i-node contains:
– File attributes (time of creation, permissions, ….)– 10 direct pointers (logical disk block ids)– 1 one-level indirect pointer (points to a disk block
which in turn contains pointers)– 1 two-level indirect pointer (points to a disk block
of pointers to disk blocks of pointers)– 1 three-level indirect pointer (points to a disk
block of pointers to disk blocks of pointers to pointers of disk blocks)
20
i-nodeFilenameTimePerm. …
Disk Block
Disk Block Disk Block
Disk Block Disk Block Disk Block
Data
Disk Block
Data
Disk Block
Data
Disk Block
Data
Disk Block
21
Tracking free blocks
• List of free blocks– bit map: used when you can store
the entire bit map in memory.– linked list of free blocks
•each block contains ptrs to free blocks, and last ptr points to another block of ptrs. (in UNIX).
•Pointer to a free FAT entry, which in turn points to another free entry, etc. (in DOS)
22
• Now we know how to retrieve the blocks of a file once we know:– The FAT entry for DOS– The i-node of the file in UNIX
• But how do we find these in the first place?– The directory where this file resides
should contain this information