nachos instructional os part 3b
play

Nachos Instructional OS: Part 3B CS 170, Tao Yang Topics File - PowerPoint PPT Presentation

Nachos Instructional OS: Part 3B CS 170, Tao Yang Topics File system implementation. Assignment 3B for File system extension 5/26/2015 2 Nachos File System Nachos Kernel Read/write Linux Two versions: openFile objects


  1. Nachos Instructional OS: Part 3B CS 170, Tao Yang

  2. Topics  File system implementation.  Assignment 3B for File system extension 5/26/2015 2

  3. Nachos File System Nachos Kernel Read/write Linux Two versions:  openFile objects openFile objects openFile objects  A ``stub'' version is simply a front-end to the Linux.  A Nachos version implemented on top of a raw disk. SynchDisk Function layers (from top to down):   FileSystem object  Directory support.  File control block (I-node) support Disk  Free block map  OpenFile objects (many)  Created by every call to open/access a file in a directory.  SynchDisk object  Created by synchDisk = new SynchDisk("DISK") in system.cc  The Disk object.  Created by disk = new Disk(name,..) in SynchDisk::SynchDisk() 5/26/2015 3

  4. Disk Size Nachos Kernel Read/write openFile objects Machine/disk.h  #define SectorSize 128 // number of bytes per disk SynchDisk sector #define SectorsPerTrack 32 // number of sectors per disk track #define NumTracks 32 // number of tracks per disk Disk #define NumSectors (SectorsPerTrack * NumTracks) // total # of sectors per disk 5/26/2015 4

  5. File System Layers in Nachos FreeMap Bitmap for Directory: Manage Nachos kernel thead 32x32 disk sectors a directory of file names FileSystem : FileHeader: i-node Directory management file create/open/delete (File control block) OpenFile: access individual file with read/write/seek. Operate on bytes. SynchDisk: synchronous access to a disk with concurrent threads. Operate on sectors. Disk: low-level interface that initiates asynchronous IO to physical disk sectors Base Operating System (Linux for our class)

  6. Operations of File System Object FileSystem(bool format).   called once at ``boot'' time.  For the stub version, just use Unix file system  Otherwise create a directory/control info.  Sector 0 is fileheader (i-node) for FreeMap.  Sector 1 is i-node for directory table. Create(char *name, int initialSize).   Create a Nachos disk file. ``initialSize'' is ignored in the stub version; Unix doesn't require it. OpenFile *Open(char *name).   Assume both read and write access.  in the stub version, Open simply opens the Unix file. Remove(char *name)  List()  5/26/2015 6

  7. Directory Object contains 10 DirectoryEntry objects (directory.h) Directory content has 10 table entries.  fit into a 128B sector.  Stored in Sector 1  Directory space is allocated in FileSystem() during initialization  … Bool inUse --- is this entry used? Int sector --- location of file header (i-node) Filename -- 9 characters+ 1 for ‘ \ n’ 128 bytes … 5/26/2015 7

  8. memory directory.cc Directory Disk Directory Limit  Block FileNameMaxLen 9 // 9 characters at most for a file name  NumDirEntries 10 // at most 10 files  Directory Object attributes  tableSize -- # of directory entries which is 10 now.  table = in-memory directory entries, each of which is for one Nachos file.  Content is copied from and copies back to a disk DirectoryFile. Operations  Directory (int size) -- Create an in-memory directory of the desired size.  FetchFrom (OpenFile *file) -- Fetch disk DirectoryFile that contains directory  entries, and copy to in-memory directory table. WriteBack(OpenFile *file) -- Write back in-memory directory content to disk  DirectoryFile called every time when a file is added or removed to directory.  FindIndex (Char *name) --Search a file string name in a directory  Add (Char *name, int sector) – Add file name into a directory with disk  sector no that contains the file header (i-node). Remove(char *name) – remove a file.  5/26/2015 8

  9. filehdr.h: File header (File control block, i-node) … int numBytes; // file size int numSectors; //sectors used Data int dataSectors[NumDirect] sector Data sector pointer 0 Data sector Data sector pointer 1 … Data Data sector pointer 29 sector memory Fit in one sector (128 bytes)  File control Operations  Disk block Allocate(BitMap *bitMap, int fileSize);  File FetchFrom (int SectorNo) -- Fetch Fileheader sector from disk.  header WriteBack(int SectorNo) -- Write back in-memory file header content to  disk ByteToSector(int offset) – Convert a file offset in bytes to a sector no  5/26/2015 9

  10. Nachos Kernel OpenFile Object Read/write openFile objects openFile objects openFile objects OpenFile(int sector)   sector – disk location of file control block.  Load FCB from disk SynchDisk create an in-memory OpenFile object Seek(int position)  Read/write in the current position  Memory Read(char *buffer, int numBytes)  File control block Write(char *buffer, int numBytes) Disk  Read/write in a specific position  OpenFile Obj ReadAt(char *buffer, int numBytes, int FilePosition).  Identify specific sectors in the file and fetch them, copy to buffer.  WriteAt(char *buffer, int numBytes, int FilePosition)  May read partially written sectors first, and then write out updated sectors.  Length(). Return the file size.  5/26/2015 10

  11. SynchDisk Object: Nachos Kernel Synchronously access a disk Read/write openFile objects Filesys/synchDisk.cc  SynchDisk ()  Called only once to create a physical disk object. Set the disk SynchDisk  interrput hander as RequstDone(). Create lock/semaphore for synchronization.  Notice that physical disk is an asynchronous device (disk requests  return immediately, and an interrupt happens later on). ReadSector(int sectorNumber, char* buffer)  Send a read request for a sector  Wait IO complete (wait for interrupt using a semaphone)  WriteSector(int sectorNumber, char* data)  Send a sector write request. Wait for interrupt.  RequestDone()  Disk interrupt handler. Wake up any thread waiting for the disk request to finish.  5/26/2015 11

  12. Nachos Kernel Disk Object Read/write openFile objects Machine/disk.h and disk.cc  Simulates the behavior of a disk I/O device.  SynchDisk  a single platter, with multiple tracks (32).  Each track contains 32 sectors  Each sector is 128 bytes Disk  Disk size = 32x32*128 =128K 128K  Asynchronous read/write with an option of disk cache Supported operations:   Disk(char *name, VoidFunctionPtr callWhenDone, int callArg)  Create a disk: just create a Unix file to simulate.  Setup a handling function (RequestDone in SynchDisk.cc) when a read/write request is done. 5/26/2015 12

  13. Nachos Kernel Operations in Disk device Read/write openFile objects ReadRequest(int sectorNumber, char *buffer)  SynchDisk  Read from the specific location of the “physical disk”.  ticks = ComputeLatency(sectorNumber, FALSE);  interrupt->Schedule(DiskDone, (int) this, ticks, DiskInt); WriteRequest(int sectorNumber, char *data) Disk   Write data to specific location of the “physical disk”.  ticks = ComputeLatency(sectorNumber, TRUE);  interrupt->Schedule(DiskDone, (int) this, ticks, DiskInt); ComputeLatency(int newSector, bool writing)   Latency= seek time + rotation time 5/26/2015 13

  14. Assignment 3B Workload  Test C programs ~cs170/nachos- projtest/proj3  Part B. ~200 in filesys (few in userprog)  Part A and B can be done in parallel  Part B may use Project 2 code without VM.  Work on filesys subdirectoy mainly.  And change system call handling code in userprog if needed (to use this extended file system).  Extend the size of each file from 4K to 100K  single indirect pointers in i-node (file control block). 5/26/2015 14

  15. Emphasis of Project 3B  Play tradeoffs  Understand the design options  Deadline-driven approach  Choose something simpler and easier to do first.  Still not enough time?  Complete with minimal efforts to pass the tests.  Hidden tests are very similar to public test cases. No complex test cases.  You are good as long as your code can run virtual memory>physical, can support files up to 100K.  Interpret the requirement towards your advantage if vague. If not specified, do something easy. 5/26/2015 15

  16. Part B: Steps for Nachos file system extension Understand how the Nachos file system operates 1. and how Nachos implements files. Modify the file system calls from Project 2 to use 2. Nachos file system Donot have to support VM (Part A/Part B can be done in 1. parallel) Modify Nachos file system so that the file size can be 3. upto 100K

  17. Files to be modified Directory filesys  filehdr.cc/.h  Support 30 direct data pointers  New: Support single indirect pointers in i-node and can  expand the file length with more sectors allocated. Write method ExtendFile() that allows a file to grow by  certain number of sectors. openfile.cc  Expand file length/allocate sectors when writing data at the  end or beyond. IndirectPointerBlock.cc (new file to add)  This class provides a way for a file header to contain not just direct sectors, but indirect blocks that each have their individual collection of sectors. This allows the file size to exceed the usual 4K. Directory userprog  exception.cc  Make sure file system calls use extended Nachos file system. 

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend