Title: EE512 System Programming
1EE512 System Programming
Lecture 9File Systems
Oct. 8, 2009 Prof. Kyu Ho Park http//core.kaist.a
c.kr
21 Files 2 Directories 3 File system
implementation 4 Example file systems
3Long-term Information Storage
- Must store large amounts of data
- Information stored must survive the termination
of the process using it - Multiple processes must be able to access the
information concurrently
4File Naming
5File Structure
- Three kinds of files
- byte sequence
- record sequence
- tree
6File Types
- (a) An executable file (b) An archive
7File 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
- 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
8File Attributes
9File Operations
- Create
- Delete
- Open
- Close
- Read
- Write
- Append
- Seek
- Get attributes
- Set Attributes
- Rename
10An Example Program Using File System Calls (1/2)
11An Example Program Using File System Calls (2/2)
12DirectoriesSingle-Level Directory Systems
- A single level directory system
- contains 4 files
- owned by 3 different people, A, B, and C
13Two-level Directory Systems
- Letters indicate owners of the directories and
files
14Hierarchical Directory Systems
- A hierarchical directory system
15Path Names
16Directory Operations
- Readdir
- Rename
- Link
- Unlink
- Create
- Delete
- Opendir
- Closedir
17File System Implementation
- A possible file system layout
18File System Layout
- Sector 0 MBR to boot the computer
- End of the MBR partition table-gtStarting and
ending address of each partition. - When the computer is booted, the BIOS reads in
and executes the MBR. - The first work of the MBR is locating the active
partition reads in its first block(boot block)
and execute it.
19File System
- 5. The program in the boot block loads OS
contained in that partition.
20Implementing Files (1)
- (a) Contiguous allocation of disk space for 7
files - (b) State of the disk after files D and E have
been removed
21Implementing Files (2)
- Storing a file as a linked list of disk blocks
22Implementing Files (3)
- Linked list allocation using a file allocation
table in RAM
23Implementing Files (4)
24Implementing Directories
- When a file is opened , the OS uses the path name
supplied by the user to locate the directory
entry. - The directory entry provides the information
needed to find the disk blocks. - Depending on the systems, the information may be
the disk address of the entire files(contiguous
allocation), the number of the first block, or
the number of the i-node.
25Directory
- The main function of the directory system is to
map the ASCII name of the file onto the
information needed to locate the data. - Attribute of a file
- files owner, creation time, modified time----
26Implementing Directories (1)
- (a) A simple directory
- fixed size entries
- disk addresses and attributes in directory entry
- (b) Directory in which each entry just refers to
an i-node
27Implementing Directories (2)
- Two ways of handling long file names in directory
- (a) In-line
- (b) In a heap
28Shared Files (1)
- File system containing a shared file
29Shared Files (2)
- (a) Situation prior to linking
- (b) After the link is created
- (c)After the original owner removes the file
30Disk Space Management (1)
Block size
- Dark line (left hand scale) gives data rate of a
disk - Dotted line (right hand scale) gives disk space
efficiency - All files 2KB
31Disk Space Management (2)
- (a) Storing the free list on a linked list
- (b) A bit map
32Disk Space Management (3)
- (a) Almost-full block of pointers to free disk
blocks in RAM - - three blocks of pointers on disk
- (b) Result of freeing a 3-block file
- (c) Alternative strategy for handling 3 free
blocks - - shaded entries are pointers to free disk blocks
33Disk Space Management (4)
- Quotas for keeping track of each users disk use
34File System Reliability (1)
File that has not changed
- A file system to be dumped
- squares are directories, circles are files
- shaded items, modified since last dump
- each directory file labeled by i-node number
35Dumping Algorithm
- From the root directory, examine all the entries
in it. All modified files are marked in its
i-node bitmap. All directories including not
modifed ones are also marked in its bitmap. - Unmarking any directories that have no modified
file or directories in them or under them. - Dumping directories that are marked.
- Dumping files that are marked.
36File System Reliability (2)
- Bit maps used by the logical dumping algorithm
37Supplement to IPC
38Monitors
- A high-level abstraction that provides a
convenient and effective mechanism for process
synchronization - Only one process may be active within the monitor
at a time
39Schematic view of a Monitor
40Condition Variables
- Condition x, y
- Two operations on a condition variable
- x.wait () a process that invokes the operation
is suspended. - x.signal () resumes one of processes (if any)
that invoked x.wait ()
41 Monitor with Condition Variables
42Monitors (1)
43Monitors (2)
44Monitors (3)
45Interprocess Communication
- Processes
- Independent Processes or Cooperating Processes
- IPC issues
- How one process can pass information to another.
- Mutual Exclusion.
- Proper sequencing when dependencies are present.
45
46Interprocess Communication(IPC)
- Message Passing Shared Memory
47Producer-Consumer Problem
- Paradigm for cooperating processes, producer
process produces information that is consumed by
a consumer process - unbounded-buffer places no practical limit on the
size of the buffer - bounded-buffer assumes that there is a fixed
buffer size
48Message Passing (1)
- Figure 2-17. The producer-consumer problem with N
messages.
. . .
49Message Passing (2)
. . .
- Figure 2-17. The producer-consumer problem with N
messages.
50Message Passing
- Message system processes communicate with each
other without resorting to shared variables - Message passing facility provides two operations
- send(message) message size fixed or variable
- receive(message)
- If P and Q wish to communicate, they need to
- establish a communication link between them
- exchange messages via send/receive
- Implementation of communication link
- physical (e.g., shared memory, hardware bus)
- logical (e.g., logical properties)
51Implementation Questions
- How are links established?
- Can a link be associated with more than two
processes? - How many links can there be between every pair of
communicating processes? - What is the capacity of a link?
- Is the size of a message that the link can
accommodate fixed or variable? - Is a link unidirectional or bi-directional?
52Direct Communication
- Processes must name each other explicitly
- send (P, message) send a message to process P
- receive(Q, message) receive a message from
process Q - Properties of communication link
- Links are established automatically
- A link is associated with exactly one pair of
communicating processes - Between each pair there exists exactly one link
- The link may be unidirectional, but is usually
bi-directional
53Indirect Communication
- Messages are directed and received from mailboxes
(also referred to as ports) - Each mailbox has a unique id
- Processes can communicate only if they share a
mailbox - Properties of communication link
- Link established only if processes share a common
mailbox - A link may be associated with many processes
- Each pair of processes may share several
communication links - Link may be unidirectional or bi-directional
54Indirect Communication
- Operations
- create a new mailbox
- send and receive messages through mailbox
- destroy a mailbox
- Primitives are defined as
- send(A, message) send a message to mailbox A
- receive(A, message) receive a message from
mailbox A
55Indirect Communication
- Mailbox sharing
- P1, P2, and P3 share mailbox A
- P1, sends P2 and P3 receive
- Who gets the message?
- Solutions
- Allow a link to be associated with at most two
processes - Allow only one process at a time to execute a
receive operation - Allow the system to select arbitrarily the
receiver. Sender is notified who the receiver
was.
56Synchronization
- Message passing may be either blocking or
non-blocking - Blocking is considered synchronous
- Blocking send has the sender block until the
message is received - Blocking receive has the receiver block until a
message is available - Non-blocking is considered asynchronous
- Non-blocking send has the sender send the message
and continue - Non-blocking receive has the receiver receive a
valid message or null
57Buffering
- Queue of messages attached to the link
implemented in one of three ways - 1. Zero capacity 0 messagesSender must wait
for receiver (rendezvous) - 2. Bounded capacity finite length of n
messagesSender must wait if link full - 3. Unbounded capacity infinite length Sender
never waits
58Bounded-Buffer Message Passing Solution
59Bounded-Buffer Message Passing Solution