程序代写代做代考 data structure The CART Device Driver

The CART Device Driver
Assignment Basics
• You are to write the file operation functions defined in the cart_driver.c ‣ Translate then file operations into CART bus operations
‣ Maintain, in the memory device, the file contents
• You must insert data, read data, and maintain a file pointer and a file allocation data.
• Your code: open, read, write, close, seek … ‣ For this assignment (#2)
• The filesystem will only have one file..
• It will not be bigger than 100k
• Your code will be exercised by the simulator given to you (it will call your functions).
Maintaining file contents
• Open prepares an empty file for reading (zero length)
• Write writes bytes into the file
• Seek seeks to a particular position in the file (end if pos > length) • Read copies up to length number of bytes from the file
• Close deletes the contents

Driver code



int32_t cart_poweron(void); – This function will initialize the CART interface basic filesystem. To do this you will execute the init CART opcode and zero all of the memory locations. You will also need to setup your internal data structures
that track the state of the filesystem.
int32_t cart_poweroff(void); – This function will show down the CART interface basic filesystem. To do this you will execute the shutdown CART opcode and close all of the files. You will also need to cleanup your internal data structures that track the state of the filesystem
int16_t cart_open(char *path); – This function will open a file (named path) 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 position should be
set to the first byte. Note that there are no subdirectories in the filesystem, just
files (so you can just treat path a filename). The function should return a unique

file handle used for subsequent operations or -1 if a failure happens.
 int16_t cart_close(int16_t fd); – 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.
 int32_t cart_read(int16_t fd, void *buf, int32_t count); – This
function should read count bytes from the file referenced by the file handleat 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.
 int32_t cart_write(int16_t fd, void *buf, int32_t count); – 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.
 int32_t cart_seek(int16_t fd, uint32_t loc); – 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.
CART HRAM System
 There are CART_MAX_CARTRIDGES cartridges in the system, each of which is numbered from 0 to CART_MAX_CARTRIDGES-1.
 Each cartridge contains are CART_CARTRIDGE_SIZE frames, each of which is numbered from 0 to CART_MAX_CARTRIDGES-1.
 A frame is memory block of CART_FRAME_SIZE bytes.
 The system maintains a current cartridge register indicating which
cartridge operations will be performed on.

CART Opcode Execution
You communicate with memory controller through a set of packed registers that encode the opcode and arguments for the operation. The “data” associated with the opcode (where needed) is communicated through the fixed sized frame buffer.
CART OpCodes

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. Initialize the disk array by calling the init & bzero opcodes
b. On writes needing “new” frames, find a location on the disk to put it, then execute the CART operations to get it to store the data
c. On writes for old frames, figure out where you put it, then execute the CART operations to overwrite the data
d. On reads, return the previously stored data in those frames
e. Power off the controller when asked to
Testing your program
• The testing of the program is performed by using the simulated workloads. The main function provided to you simple calls the function. To test the program, you execute the simulator using the -v option, as:

./cart_sim-v workload/cmpsc311-f16-assign2-workload.txt
• If you have implemented everything correctly, the log should display the following message:
CART simulation: all tests successful!!!.
Getting started
• 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
• Note: you may have to install libgcrypt-dev via apt-get.
Hints
 Use the logMessage interface to log information about how your program is running.
 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.
First functions…
• The first functions you should write should create a register structure and extract a register structure:
CartXferRegister create_cart_opcode(…?) { ???
}
??? extract_cart_opcode(CartXferRegister resp, …) {
??? }
!! More information for starting the program
1) Likely because of formatting, copying and pasting commands from the terminal may cause problems. You are much better off typing the commands in directly.
2) A reminder. You may have to install some tools the first time for the compilation to work. In particular, you may have to install some tools using the following command:
sudo apt-get install libgcrypt-dev
sudo apt-get install libcurl4-gnutls-dev
4) There was a typo in the original assignment. For the record, here are the fields of the packed registers:

Bits Register (note that top is bit 0) —— ———————————–
0-7 – KY1 (Key Register 1) 7-15 – KY2 (Key Register 2)
16 – RT1 (Return code register 1) 17-32 – CT1 (Cartridge register 1) 32-47 – FM1 (Frame register 1) 48-63 – UNUSED