Lecture 19 - Suraj @ LUMS

Download Report

Transcript Lecture 19 - Suraj @ LUMS

Friday, July 07, 2006
“Vision without action is a
daydream,
Action without a vision is a
nightmare.”
- Japanese Proverb
1
Segmentation vs. Paging
 Linear address spaces?
 Can address space exceed the size of
physical memory?
 Can procedures and data be distinguished
separately?
 Is sharing of procedures facilitated?
2
Long-term Information Storage
1. Must store large amounts of data
2. Information stored must survive the
termination of the process using it
3. Multiple processes must be able to access
the information concurrently
3
File naming
 Shield user from details of how
information is stored
 Names can be as long as 255 characters
 Upper case and lower case
4
Extensions
 Unix does not enforce extensions

Convenience for the user
 May be required by programs e.g. C
compilers
 Windows is aware of extensions and we
can specify which program is associated
with an extension
5
File Structure
 Three kinds of files

Unstructured sequence of bytes
• OS does not know what is inside the file
• Any meaning is imposed by the user programs
• Approach used by UNIX and Windows

Record sequence
• Fixed length records

Tree
• Record retrieved through a key
• Large mainframe computers for commercial data
processing
6
 The DECSYSTEM-20 minicomputer
example.
7
 Flexibility lost if OS enforces all file types
8
 Every Operating system must recognize
one file type: its own executable file.
 Executable binary file in UNIX


Will execute file only if it has a proper
format
Header with Magic number, sizes of text and
data segments, address where execution
starts etc.
9
File Access
 Sequential access



read all bytes/records from the beginning
cannot jump around, could rewind or back up
convenient when medium was mag tape
 Random access (Modern OSs)



bytes/records read in any order
essential for data base systems
read can be …
• move file marker (seek), then read or …
• read and then move file marker
10
File Attributes







Name
Owner
Date and time of creation
Modification
Protection information
Size
…
11
File Operations
1.
2.
3.
4.
5.
6.
Create
Delete
Open
Close
Read
Write
7.
8.
9.
10.
11.
Append
Seek
Get attributes
Set Attributes
Rename
12
 open system call


Fetch file attributes and disk addresses into
main memory do that later accesses can be
carried out quickly.
File descriptor (small integer for use in
subsequent operations)
 close system call

file should be closed to free up internal disk
space.
13
Directories
Single-Level Directory Systems
 A single level directory system


contains 4 files
owned by 3 different people, A, B, and C
14
Two-level Directory Systems
Letters indicate owners of the directories and files
Shared system programs
15
Hierarchical Directory Systems
A hierarchical directory system (used in
modern file systems)
16
Path Names
A UNIX directory tree
17
File System Implementation
A possible file system layout
Master Boot Record, usually in sector 0, is used to boot the computer.
One partition is marked as active.
Super block contains key parameters about the file system, such as
18
number of blocks, magic number etc.
Implementing Files
(a) Contiguous allocation of disk space for 7 files
(b) State of the disk after files D and E have been removed
19
Contiguous allocation
 Simple to implement
 Easy to locate blocks given the disk address
of first block
 Read performance for the entire file is very
good

Why? How many Seeks?
20
Contiguous allocation
 Problems: Fragmentation
 Files can grow in size
 Is declaring the maximum size of file a
good idea?
21
Contiguous allocation
 Widely used on CD-ROMs
22
Implementing Files (cont’d)
Storing a file as a linked list of disk blocks
23
 No space lost to external fragmentation.
 We need to store only the disk address of
the first block.
 Random access is slow: To get to block N,
must read n-1 blocks before it.
 Amount of data stored is no longer power of
two because the pointer takes some bytes.
24
Implementing Files (cont’d)
Take the pointer
away from each
disk block and
put it in a table in
memory.
We need to store
only the starting
block number.
Linked list allocation using a file allocation table in RAM
25
FAT
 Main disadvantage:



Entire table must be kept in memory
The table holding linked lists is proportional to
the size of disk
40GB disk with 1KB block size  40 million
entries
26
Implementing Files (cont’d)
Index-node or i-node
A data structure
associated with each file
to keep track of which
blocks belong to which
file.
I-node need only be in
memory when the
corresponding file is
open.
Using i-nodes require an
array that is proportional
to the maximum number
of files that may be open
at once.
An example i-node
27
 Nearly all file system store files as fixedsize blocks.
 Internal fragmentation
 Small blocks


Good for disk utilization
Bad for performance
 In Unix: 1KB blocks are commonly used
28
 Every file in Unix has a unique number (inumber) that identifies it.
 This i-number is used as an index into the
table of i-nodes.
 A directory is simply a file that contains a
set of (i-number, file name) pairs.
29
Implementing Directories
(a) A simple directory (Windows)
fixed size entries
disk addresses and attributes in directory entry
(b) Directory in which each entry just refers to an i-node
30
(Unix)
Shared Files
File system containing a shared file
31
(a) Two directories before linking
/usr/jim/memo to ast's directory
(b) The same directories after linking
32
Shared Files
Hard Link
(a) Situation prior to linking
(b) After the link is created
(c) Increments the counter in the file’s i-node
33
Symbolic linking
 Create a new file of type LINK.
 This file contains just the path name of the
file to which it is linked
34
Links
Hard links
 What if the original owner removes the file.
 Owner’s quota being used
Symbolic links
 File to store path takes up one disk block of
space.
 Extra i-node needed for each symbolic link.
 Need to parse the path to get to its i-node.
35
Sharing Files
Two processes can share a mapped file.
A new file mapped simultaneously into two processes
36
Unix System calls
 mmap
 unmap
37
UNIX File System
Disk layout in classical UNIX systems
38
UNIX File System
The relation between the file descriptor table, the
39
open file description