Operating System代写:CMPSC311 Hierarchical RAM Backed Filesystem

根据提供的start code代写一个叫HRAM的内存管理系统,完成对应的读写等函数即可。

Requirement

All remaining assignments for this class are based on the creation and extension of a user‐space device driver for a in memory filesystem that is built on top of a hierarchical random access memory system (HRAM). At the highest level, you will translate file system commands into memory frame level memory operations (see memory interface specification below). The file system commands include open, read, write, seek and close for files that are written to your file system driver. These operations perform the same as the normal UNIX I/O operations, with the caveat that they direct file contents to the HRAM storage device instead of the host filesystem.

System and Project Overview

You are to write a basic device driver that will sit between a virtual application and virtualized hardware. The application makes use of the abstraction you will provide called HRAM “cartridge” memory system (CART).

Described in detail below, we can see three layers. The CART application is provided to you and will call your device driver functions with the basic UNIX file operations (open, …). You are to write the device driver code to implement the file operations. Your code will communicate with a virtual controller by sending opcodes and data over an I/O bus.

All of the code for application (called the simulator) and CART memory system is given to you. Numerous utility functions are also provided to help debug and test your program, as well as create readable output. Sample workloads have been generated and will be used to extensively test the program. Students that make use of all of these tools (which take a bit of time up front to figure out) will find that the later assignments will become much easier to complete.

The Cartridge Memory System Driver (CART)

You are to write the driver that will implement the the basic UNIX file interface using the memory system. You will write code to implement the filesystem, and make several design decisions that will determine the structure and performance of the driver. In essence you will write code for the read, write, open, close and other high level filesystem functions. Each function will translate the call into low‐level operations on the device (see below).

The functions you will implement are:

  • 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 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.

  • 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 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.

  • 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.

The key to this assignment if figuring out what you need to do to implement these functions. You are specifically not given guidance on how to do it. You need to (a) maintain information about current files in the file system, (b) allocate parts if the memory system to place data, (c) copy data into and out of the memory system as needed to serve reads and writes. How you do this is up to you, but think carefull about it before beginning to code. What is important is that the code you write will be built upon the whole semester.

The Cartridge Memory System (CART)

You will implement your driver on top of the CART memory system (which is referred to throughout simply as the CART). The CART is a hierarchical memory system, which means that there are multiple levels of memory organization. In the case of the CART, there are three levels: the system as a whole consists of multiple cartridges, each of which contain multiple frames. Each frame is a fixed byte sized memory block. Some key facts of the system include (see cart_controller.h for definitions):

  • 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.

Honors Option

The device driver should implement three different frame allocation strategies. They should be defined by adding an enumerated type and associated variable that is used to tell the driver which allocation to use for which run. The allocation strategies include:

  • CARTALLOC_LINEAR ‐ this allocation strategy should allocate frame on the first cartridge until full, then second, then third, and so on. The frame on each cartridge should be allocated from highest to lowest, in reverse order.
  • CARTALLOC_BALANCED ‐ this allocation strategy should allocate frames evenly across the cartridges (round‐robin). The frames on each cartridge should be allocated from highest to lowest.
  • CARTALLOC_RANDOM ‐ this allocation strategy should allocate frames randomly across the cartridges. The frames on each cartridge should be allocated randmonly as well.

You need to modify the main program to accept run‐time parameters “‐‐linear”, “‐‐balanced, and “‐‐random”. The program should fail if more than one of these is provided, and the driver should be configured with the appropriate value if the parameter is provided. The driver should default to random.