Project 3 File System and IO - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Project 3 File System and IO

Description:

... a simple file system using the driver. Overall Organization. File ... Disk is viewed as a sequential file of data blocks. Length of a block = length of a sector ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 21
Provided by: dc7
Category:
Tags: file | project | system

less

Transcript and Presenter's Notes

Title: Project 3 File System and IO


1
Project 3 File System and I/O
  • Assignment
  • Design and implement a driver for a (simulated)
    magnetic disk
  • Design and implement a simple file system using
    the driver
  • Overall Organization

2
Organization of the disk
  • A disk consist of surfaces (num of surfaces)
  • Surfaces consist of tracks
  • Tracks consist of sectors (num of sectors)
  • Sectors consists of bytes (len of a sector)
  • Tracks with the same diameter form a cylinder
    (num of cylinders)

3
Disk Operations
  • SEEK move the read/write arm to a desired
    cylinder
  • READ transfer one block of data from disk to
    memory
  • WRITE transfer one block of data from memory to
    disk
  • REPORT indicate completion status

4
Disk Controller (interface 3) See Using the
disk controller
  • Registers
  • OP_REG SEEK, READ, WRITE, REPORT
  • CYL_REG cylinder
  • SURF_REG surface
  • SECT_REG sector
  • MEM_REG MM address
  • BUSY true/false
  • STAT completion status

5
Disk Controller functions
  • Initialize a disk init_disk(surf, cylinder,
    sector, block, block_len)
  • disk retains its content indefinitely
  • Set registers write_reg(reg, content)
  • Can not set status register
  • Read registers read_reg(reg)
  • Reg STAT or BUSY
  • Start disk operation start()
  • May be ignored if BUSYtrue
  • Request interrupt request_int()
  • May block the current process

6
An example of a disk operation
  • Set necessary registers OP, SURF, CYL, SECT, MEM
  • Start disk operation
  • Wait until BUSYfalse by requesting interrupt
  • Or polling the completion status
  • Note STAT register is not set automatically it
    must be requested
  • Place REPORT into OP_REG
  • Start()
  • Busy wait until BUSYFALSE
  • Read STAT register
  • Seek, read, and write operation may fail
    unpredictably repeat if necessary

7
Disk Driver (interface 2)
  • Disk is viewed as a sequential file of data
    blocks
  • Length of a block length of a sector
  • Blocks are mapped onto the disk starting with
    cylinder 0, surface 0, sector 0
  • Data access
  • FS requests a block by specifying a block
  • Driver transforms it to cylinder/surface/sector
    address and commands disk controller

8
Disk Driver Functions
  • Read a block
  • int read_block( int b, char p)
  • Copy the logical block b from disk to memory
    starting at p
  • Return 0 if successful -1 otherwise
  • Write a block
  • int write_block( int b, constant char p)
  • Copy the logical block b from memory starting at
    p to disk
  • Return 0 if successful -1 otherwise

9
Block Numbering Scheme
  • Start with cylinder 0, surface 0, sector 0 ?block
    0
  • Fill all sectors within a track before move to
    the next track
  • Fill tracks within a cylinder before move to the
    next cylinder
  • Formula
  • Block(CylNUM_OF_SURFSurf)
  • NUM_OF_SECTORSect
  • Sect Block mod NUM_OF_SECT
  • Surf Block / NUM_OF_SECT mod NUM_OF_SURF
  • Cyl Block / (NUM_OF_SECTNUM_OF_SURF)

10
File System
  • create(file_name) return ok/error
  • destroy(file_name) return ok/error
  • open(file_name) return index
  • close(index) return ok/error
  • read(index, mem_area, count) return bytes read
  • write(index, mem_area, count) return bytes
    written
  • lseek(index, pos) return ok/error
  • directory return ok/error

11
Organization of the file system
Track 0 on Cylinder 0
File descriptors
Track 1/Cylinder 0
Data blocks
bit map

Descriptor for FS directory
Each descriptor
Block numbers
length
File length in bytes
12
FS Directory
  • Only one root directory
  • A regular file
  • Described by the first descriptor
  • Contains array of entries
  • Each entry record info of a file
  • File name
  • Index of the descriptor

13
Create a file
  • Find a free file descriptor
  • Find a free directory entry
  • Fill both entries

i
14
Destroy a file
  • Find file descriptor by searching directory
  • Remove directory entry
  • Remove file descriptor
  • Update bit map

15
Open a file
OFT
Fixed length array
Current position
index
  • Search directory to find the index of file
    descriptor
  • Allocate a free OFT entry
  • Fill in current position (0) and file descriptor
    index
  • Read in first block into the buffer ( read-ahead
    )
  • Return OFT index

16
Close a file
  • Write buffer to disk
  • Delete OFT entry

17
Read a file
  • Compute position in the r/w buffer
  • Copy from buffer to memory until
  • Desired count is reached update current pos, or
  • End of file is reached update current pos, or
  • End of buffer is reached
  • Write the buffer into disk
  • Read the next block
  • Continue copying

18
Write a file
  • Write into buffer
  • When full, write buffer to disk
  • Allocate new block if necessary
  • Change file descriptor
  • Change bit map
  • Update file length in descriptor if necessary

19
Seek a file
  • If the new position is not within the current
    block
  • Write the buffer into disk
  • Load the new block
  • Set the current position to be the new position

20
List the directory
  • Read directory file
  • For each entry do
  • Print file name
  • Find file descriptor print file length
Write a Comment
User Comments (0)
About PowerShow.com