Microsoft Word - Assignment2.docx LionCloud (v1.0) \\\\\\ ` cmpsc311-sp20-lcloud Overview • Idea you are to maintain the correct file contents in a Cloud Based virtual storage device. • You will write...

1 answer below »
Instructions in file



Microsoft Word - Assignment2.docx LionCloud (v1.0) \\\\\\ ` cmpsc311-sp20-lcloud Overview • Idea you are to maintain the correct file contents in a Cloud Based virtual storage device. • You will write code to communicate with a devices over a a virtualized bus that will store file-system data. • 3 things to know ‣ How file I/O works ‣ How the LoinCloud bus works ‣ How to make the memory device stuff look like files LC Simulator (provided) LC Filesystem Driver (your code) LC LC Storage Device (device I/O bus) Assignment Basics • You are to write the file operation functions defined in the lcloud_filesys.c ‣ Translate then file operations into device IO operations ‣ Maintain, in the memory device, the file contents • You must insert data, read data, and maintain a file handle and a file allocation data. • Your code: open, read, write, close, seek … • Your code will be exercised by the simulator given to you (it will call your functions and verify the data you are returning is correct). Your driver • LcFHandle lcopen( const char *path ); - This function will open a file (named path, e.g.,) in the filesystem. If the file does not exist, it should be created and set to zero length. If it does exist, it should be opened and its read/write postion should be set to the first byte. Note that there are no subdirectories in the filesystem, just files (so you can treat the path as a filename). The function should return a unique file handle used for subsequent operations or -1 if a failure occurs. • int lcclose( LcFHandle fh ); - This function closes the file referenced by the file handle that was previously open. The function should fail (and return -1) if the file handle is bad or the file was not previously open. • int lcread( LcFHandle fh, char *buf, size_t len ); - This function should read count bytes from the file referenced by the file handle at the current position. Note that if there are not enough bytes left in the file, the function should read to the end of the file and return the number of bytes read. If there are enough bytes to fulfill the read, the function should return count. The function should fail (and return -1) if the file handle is bad or the file was not previously open. Your driver (cont.) • int lcwrite( LcFHandle fh, char *buf, size_t len ); - The function should write count bytes into the file referenced by the file handle. If the write goes beyond the end of the file the size should be increased. The function should always return the number of bytes written, e.g., count. The function should fail (and return -1) if the file handle is bad or the file was not previously open. • int lcseek( LcFHandle fh, size_t off ); - The function should set the current position into the file to loc, where 0 is the first byte in the file. The function should fail (and return -1) if the loc is beyond the end of the file, the file handle is bad or the file was not previously open. • int lcshutdown( void ); - - The function should shut down the system, including powering off the devices and closing all files. Maintaining file contents len=0, pos=0 open(“file.txt”) X X X X X len=5, pos=5 write(“XXXXX”, 5) X X X X X len=5, pos=2 seek(2) X X X X X len=5, pos=5 read(4) • Open prepares an empty file for reading (zero length) • Write writes bytes into the file • Seek seeks to a position in the file (end if pos > length) • Read copies up to length number of bytes from the file • Close deletes the contents Lion Cloud Devices • Each device has LC_DEVICE_NUMBER_SECTORS sectors and LC_DEVICE_NUMBER_BLOCKS blocks. The blocks and sectors are zero indexed. • A frame is memory block of LC_DEVICE_BLOCK_SIZE bytes. • You can assume that there is only one device in the system. LC Sector 0 Block 0 Block 1 Block 2 Block b-1 … Sector 1 Block 0 Block 1 Block 2 Block b-1 … Sector s-1 Block 0 Block 1 Block 2 Block b-1 … … CART Opcode Execution You communicate with devices through a set of registers of different sizes that encode the opcode and arguments for the operation. The “data” associated with the opcode (where needed) is communicated through the fixed sized transfer buffer (LC_DEVICE_BLOCK_SIZE). LCloudRegisterFrame lcloud_io_bus( LCloudRegisterFrame frm, void *xfer ); B0 C0 C1 C2 D0 D1 4-bits 8-bits 8-bits 8-bits 16-bits 16-bits B1 Most significant bit Least significant bit Using the Lion Cloud Registers • There are 7 registers: B0/B1 (4 bits), C0/C1/C2 (8 bits), and D0/D1 (16 bits) ‣ B0 is always used to indicate who is the sender of the message. It is always 0 when you are sending, 1 when it is the devices responding. ‣ B1 always contains a return/status code, should always be 0 when sending to devices. 1 is acknowledge/success from device, anything else is failure. ‣ C0 is always the operation code (see LcOperationCode type in lcloud_controller.h) ‣ The rest of the registers are dependent on the type of operation being performed (see next) B0 C 0 C 1 C 2 D0 D1 4-bits 8-bits 8-bits 8-bits 16-bits 16-bits B1 M ost significant bit Least significant bit Operation types / the IO bus • LC_POWER_ON - Initialize interface to a given device ‣ All other registers should be 0 on both send and receive • LC_POWER_OFF - Power off the device ‣ All other registers should be 0 on both send and receive • LC_DEVPROBE - Probe the bus to see what devices are present ‣ d0 - contains a bit mask of present devices, where device there are a possible 16 devices, where the bit 2^x=1 indicates that device ID x is present. For example if the 2^4 (16) is present, then you know device with ID 4 is on the bus. Operation types / the IO bus (cont.) • LC_BLOCK_XFER - Transfer a block to the device ‣ c1 - the device ID for the device to read from ‣ c2 - LC_XFER_WRITE for write, LC_XFER_READ for read ‣ d0 - sector to read/write from ‣ d1 - block to read/write from LCloudRegisterFrame lcloud_io_bus( LCloudRegisterFrame frm, void *xfer ); xfer is NULL for every command except LC_BLOCK_XFER, in which you put a pointer to a buffer to read or write from. Summary • To summarize, your code will receive commands from the virtual application (simulator). It will do the following functions to implement the device driver: a. Power on the devices using the power on b. Probe the bus to see what devices are available (one) c. On writes, you have to figure out where to place the data (and remember it) d. On reads, return the previously stored data in those blocks e. Power off the controller when asked to Start POWER ON PROBE BUS OPEN READ/WRITE CLOSE Honors option • Honors option: When you receive the indication to shut down the device cluster, you must go back and erase all of the data you wrote to the array. That is you must write all zeros you previously used in any write operation, regardless of what file it may have been mapped to. The program on exit will indicate via the log whether you have successfully completed the honors option: Testing your program • The testing of the program is performed by using the simulated workloads. The main function provided to you simply calls the simulator. To test the program, you execute the simulator using the -v option, as: • If you have implemented everything correctly, the log should display the following message: ./lcloud_sim -v cmpsc311-assign2-manifest.txt cmpsc311-assign2-workload.txt LionCloud simulation completed successfully!!! Getting started … • Get the file from the canvas page. • Change into your development directory and unpack the file: % cd ~/cmpsc311 % cp assign2-starter.tgz cmpsc311 % cd cmpsc311 % tar xvfz assign2-starter.tgz % cd assign2 % make Install libraries • You will have to install some libraries you will need for the assignment. Run the following command in your terminal window. sudo apt-get install libcurl4-gnutls-dev libgcrypt-dev Hints • Use the logMessage interface to log information about how your program is running. (see next page) • Carefully read and understand the error messages that are being written to the log. • Review the simulator code to see how the interfaces in the program should operate. !!!! logMessage() • Available in the cmpsc311_log.h – provides you a way to print out information from your code, and works like printf() ‣ logMessage( LEVEL, “Stuff … %d”, parameters ); ‣ Use the “LcDriverLevel” level for your code (global value) logMessage(lcDriverLevel, “This is my code %d [%s]”, val, str ); Open() pseudo-code Open (path) { 1) check if file already open (fail if already open) 2) pick unique file handle 3) save filename and file information locally 4) set file pointer to first byte 5) if
Answered Same DayMar 09, 2021

Answer To: Microsoft Word - Assignment2.docx LionCloud (v1.0) \\\\\\ ` cmpsc311-sp20-lcloud Overview • Idea you...

Ria answered on Mar 16 2021
135 Votes
lcloud_filesys.c
////////////////////////////////////////////////////////////////////////////////
//
// File : lcloud_filesys.c
// Description : This is the implementation of the Lion Cloud device
// filesystem interfaces.
//
// Author : Judy Ng
// Last Modified : February 20, 2020
//
// Include files
#include
#include
#include
// Project include files
#include
#include
//
// File system interface implementation
////////////////////////////////////////////////////////////////////////////////
//
// Function : lcopen
// Description : Open the file for for reading and writing
//
// Inputs : path - the path/filename of the file to be read
// Outputs : file handle if successful test, -1 if failure
LcFHandle lcopen( const char *path ) {
// for reading and writing
fstream file;
// file open
file.fopen(path,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here