EE512 System Programming - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

EE512 System Programming

Description:

Information stored must survive the termination of the process using it ... When the computer is booted, the BIOS reads in and executes the MBR. ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 60
Provided by: core3
Category:

less

Transcript and Presenter's Notes

Title: EE512 System Programming


1
EE512 System Programming
Lecture 9File Systems
Oct. 8, 2009 Prof. Kyu Ho Park http//core.kaist.a
c.kr
2
  • File Systems

1 Files 2 Directories 3 File system
implementation 4 Example file systems
3
Long-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

4
File Naming
  • Typical file extensions.

5
File Structure
  • Three kinds of files
  • byte sequence
  • record sequence
  • tree

6
File Types
  • (a) An executable file (b) An archive

7
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
  • 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

8
File Attributes
  • Possible file attributes

9
File Operations
  • Create
  • Delete
  • Open
  • Close
  • Read
  • Write
  • Append
  • Seek
  • Get attributes
  • Set Attributes
  • Rename

10
An Example Program Using File System Calls (1/2)
11
An Example Program Using File System Calls (2/2)
12
DirectoriesSingle-Level Directory Systems
  • A single level directory system
  • contains 4 files
  • owned by 3 different people, A, B, and C

13
Two-level Directory Systems
  • Letters indicate owners of the directories and
    files

14
Hierarchical Directory Systems
  • A hierarchical directory system

15
Path Names
  • A UNIX directory tree

16
Directory Operations
  • Readdir
  • Rename
  • Link
  • Unlink
  • Create
  • Delete
  • Opendir
  • Closedir

17
File System Implementation
  • A possible file system layout

18
File 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.

19
File System
  • 5. The program in the boot block loads OS
    contained in that partition.

20
Implementing Files (1)
  • (a) Contiguous allocation of disk space for 7
    files
  • (b) State of the disk after files D and E have
    been removed

21
Implementing Files (2)
  • Storing a file as a linked list of disk blocks

22
Implementing Files (3)
  • Linked list allocation using a file allocation
    table in RAM

23
Implementing Files (4)
  • An example i-node

24
Implementing 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.

25
Directory
  • 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----

26
Implementing 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

27
Implementing Directories (2)
  • Two ways of handling long file names in directory
  • (a) In-line
  • (b) In a heap

28
Shared Files (1)
  • File system containing a shared file

29
Shared Files (2)
  • (a) Situation prior to linking
  • (b) After the link is created
  • (c)After the original owner removes the file

30
Disk 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

31
Disk Space Management (2)
  • (a) Storing the free list on a linked list
  • (b) A bit map

32
Disk 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

33
Disk Space Management (4)
  • Quotas for keeping track of each users disk use

34
File 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

35
Dumping 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.

36
File System Reliability (2)
  • Bit maps used by the logical dumping algorithm

37
Supplement to IPC
38
Monitors
  • 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

39
Schematic view of a Monitor
40
Condition 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
42
Monitors (1)
43
Monitors (2)
44
Monitors (3)
45
Interprocess 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
46
Interprocess Communication(IPC)
  • Message Passing Shared Memory

47
Producer-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

48
Message Passing (1)
  • Figure 2-17. The producer-consumer problem with N
    messages.

. . .
49
Message Passing (2)
. . .
  • Figure 2-17. The producer-consumer problem with N
    messages.

50
Message 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)

51
Implementation 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?

52
Direct 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

53
Indirect 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

54
Indirect 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

55
Indirect 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.

56
Synchronization
  • 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

57
Buffering
  • 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

58
Bounded-Buffer Message Passing Solution
  • The Producer

59
Bounded-Buffer Message Passing Solution
  • The Consumer
Write a Comment
User Comments (0)
About PowerShow.com