DOC

Nachos File System

By Lorraine Payne,2014-12-24 21:50
12 views 0
Nachos File System

    实验四?Nachos File System 实验目的?

     The purpose of the laboratory session is to study the functionality of the file system

    in Nachos,

    实验内容?

     In this laboratory session ,you will run the commands of the Nachos file system and

    watch the effects on the simulated hard disk in Nahos,Onthe completion of this

    laboratory session,you should know :

     1.what is the functionality of the Nachos file system

     2.how to examine the contents of the simulated hard disk in Nachos

    实验步骤及结果?

    .Compliling the Nahcos file system a) 进入目录?../filesys

    b) 执行命令make

    c) 查看Makefile.local的内容

    ifndef MAKEFILE_FILESYS_LOCAL

    define MAKEFILE_FILESYS_LOCAL

    yes

    endef

# Add new sourcefiles here.

CCFILES +=bitmap.cc\

     directory.cc\

     filehdr.cc\

     filesys.cc\

     fstest.cc\

     openfile.cc\

     synchdisk.cc\

     disk.cc

ifdef MAKEFILE_USERPROG_LOCAL

    DEFINES := $(DEFINES:FILESYS_STUB=FILESYS) else

    INCPATH += -I../userprog -I../filesys DEFINES += -DFILESYS_NEEDED -DFILESYS endif

endif # MAKEFILE_FILESYS_LOCAL

    .Usage of Nahcos File System Commands a) 执行./nachos [-d f] -f命令;该命令用来格式化硬盘DISK

    b) 执行./nachos [-d f] -cp /root/Desktop/ring.cc xiao,cc:将文件ring.cc存到nachos

    文件xiao.cc

c) 用命令 ./nachos [-d f] -l来查看系统中的nachos文件

     [root@localhost filesys]# ./nachos [-d f] -l *** thread 0 looped 0 times

    *** thread 1 looped 0 times

    *** thread 1 looped 1 times

    *** thread 0 looped 1 times

    *** thread 1 looped 2 times

    *** thread 0 looped 2 times

    *** thread 1 looped 3 times

    *** thread 0 looped 3 times

    *** thread 1 looped 4 times

    *** thread 0 looped 4 times

    xiao,cc

    第二步执行成功。

    d) 执行./nachos [-d f] -p xiao,cc命令?用来显示文件的内容

    [root@localhost filesys]# ./nachos [-d f] -p xiao,cc *** thread 0 looped 0 times

    *** thread 1 looped 0 times

    *** thread 1 looped 1 times

    *** thread 0 looped 1 times

    *** thread 1 looped 2 times

    *** thread 0 looped 2 times

    *** thread 1 looped 3 times

    *** thread 0 looped 3 times

    *** thread 1 looped 4 times

    *** thread 0 looped 4 times

    // ring.cc

    // Routines to implement a ring buffer for producer and consumer

    // problem.

    //

    // Copyright (c) 1995 The Regents of the University of Southern Queensland.

    // All rights reserved. See copyright.h for copyright notice and limitation

    // of liability and disclaimer of warranty provisions.

extern "C" {

    #include <stdio.h>

    extern int exit(int st);

    }

#include "ring.h"

//----------------------------------------------------------------------

    // slot::slot

    // The constructor for the slot class.

    //----------------------------------------------------------------------

slot::slot(int id, int number)

    {

     thread_id = id;

     value = number;

    }

    //---------------------------------------------------------------------- // Ring::Ring

    // The constructor for the Ring class. Note that it doesn't have a // return type.

    //

    // "sz" -- maximum number of elements in the ring buffer at any time //----------------------------------------------------------------------

Ring::Ring(int sz)

    {

     if (sz < 1) {

     fprintf(stderr, "Error: Ring: size %d too small\n", sz);

     exit(1);

     }

     // Initialize the data members of the ring object.

     size = sz;

     in = 0;

     out = 0;

     buffer = new slot[size]; //allocate an array of slots. }

    //---------------------------------------------------------------------- // Ring::~Ring

    // The destructor for the Ring class. Just get rid of the array we // allocated in the constructor.

    //----------------------------------------------------------------------

Ring::~Ring()

    {

     // Some compilers and books tell you to write this as:

     // delete [size] stack;

     // but apparently G++ doesn't like that.

     delete [] buffer;

    }

//----------------------------------------------------------------------

    // Ring::Put

    // Put a message into the next available empty slot. We assume the

    // caller has done necesaary synchronization. //

    "message" -- the message to be put in the buffer //

    //----------------------------------------------------------------------

void

    Ring::Put(slot *message)

    {

     buffer[in].thread_id = message->thread_id;

     buffer[in].value = message->value;

     in = (in + 1) % size;

    }

//----------------------------------------------------------------------

    // Ring::Get

    // Get a message from the next full slot. We assume the // caller has done necesaary synchronization. //

    // "message" -- the message from the buffer //----------------------------------------------------------------------

void

    Ring::Get(slot *message)

    {

     message->thread_id = buffer[out].thread_id;

     message->value = buffer[out].value;

     out = (out + 1) % size;

    }

int

    Ring::Empty()

    {

    // to be implemented

    }

int

    Ring::Full()

    {

// to be implemented

    }

No threads ready or runnable, and no pending interrupts.

    Assuming the program completed. Machine halting!

Ticks: total 158300, idle 148300, system 10000, user 0

    Disk I/O: reads 296, writes 0

    Console I/O: reads 0, writes 0

    Paging: faults 0

    Network I/O: packets received 0, sent 0

Cleaning up...

    e) 执行./nachos [-d f] -r xiao,cc命令?用来删除该文件;此时再用./nachos [-d f]

    -l来查看系统中的nachos文件;可发现xiao.cc文件已经不存在。

    f) 执行./nachos [-d f] -D命令?用来打印包括the bitmap,the file headers,the

    directory and the files的整个文件系统的内容。

    g) 执行./nachos [-d f] -t命令?用来测试文件系统的性能。

    .UNIX command od

    a) read the manual page of od

    b) 执行命令od -c test/small

    0000000 T h i s i s t h e s p

    r i

    0000020 n g o f o u r d i s c

    o n

    0000040 t e n t . \n

    0000046

    .Testing Nachos File System

    a) 执行命令./nachos -f 可以在当前目录中创建硬盘DISK

    b) 执行命令./nachos -D

    [root@localhost filesys]# ./nachos -D *** thread 0 looped 0 times

    *** thread 1 looped 0 times

    *** thread 1 looped 1 times

    *** thread 0 looped 1 times

    *** thread 1 looped 2 times

    *** thread 0 looped 2 times

    *** thread 1 looped 3 times

    *** thread 0 looped 3 times

    *** thread 1 looped 4 times

    *** thread 0 looped 4 times

    Bit map file header:

FileHeader contents. File size: 128. File blocks:

    2

    File contents:

    \1f\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 Directory file header:

    FileHeader contents. File size: 200. File blocks:

    3 4

    File contents:

    \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0

    Bitmap set:

    0, 1, 2, 3, 4,

    Directory contents:

No threads ready or runnable, and no pending interrupts.

    Assuming the program completed.

    Machine halting!

Ticks: total 5500, idle 5030, system 470, user 0

    Disk I/O: reads 10, writes 0

    Console I/O: reads 0, writes 0

    Paging: faults 0

    Network I/O: packets received 0, sent 0

Cleaning up...

    c) 执行命令od -c DISK

    [root@localhost filesys]# od -c DISK

    0000000 253 211 g E 200 \0 \0 \0 001 \0 \0 \0 002 \0 \0 \0 0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 *

    0000200 \0 \0 \0 \0 310 \0 \0 \0 002 \0 \0 \0 003 \0 \0 \0 0000220 004 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 0000240 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 *

    0000400 \0 \0 \0 \0 037 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 0000420 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 d) 执行./nachos -cp test/small small,./nachos -l,./nachos -p,./nachos -D去检验

    [root@localhost filesys]# ./nachos -l

    *** thread 0 looped 0 times

*** thread 1 looped 0 times

    *** thread 1 looped 1 times

    *** thread 0 looped 1 times

    *** thread 1 looped 2 times

    *** thread 0 looped 2 times

    *** thread 1 looped 3 times

    *** thread 0 looped 3 times

    *** thread 1 looped 4 times

    *** thread 0 looped 4 times

    small,

    .Questions

    a) 查看./nachos -Dod -c DISK的执行结果可看到在硬盘DISK中的文件

    Name: small,, Sector: 5

    FileHeader contents. File size: 38. File blocks:

    6

    File contents:

    This is the spring of our discontent.\a

b) What are the sector numbers of data blocks for file big?

    Name: big, Sector: 7

    FileHeader contents. File size: 608. File blocks:

    8 9 10 11 12

    File contents:

    This is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThisis the spring of our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\aThis is the springof our discontent.\aThis is the spring of our discontent.\aThis is the spring of our discontent.\a

    c) What is the sector number of the disk to store the file header for file big? 通过Name: big, Sector: 7

    FileHeader contents. File size: 608. File blocks:可看出文件头存在扇区7里。

    d) The sector size of the Nachos hard disk is 128 bytes.Could you check the result

    of od -c DISK to make sure that the data blocks and the file header of big are in

    the right places in the disk ?

    0000600 \0 \0 \0 \0 001 \0 \0 \0 005 \0 \0 \0 s m a l 0000620 l , \0 \0 \0 \0 \0 \0 001 \0 \0 \0 \a \0 \0 \0 0000640 b i g \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0

    0000660 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0

Report this document

For any questions or suggestions please email
cust-service@docsford.com