Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implementing a FAT Filesystem In this assignment, we will be creating a virtual filesystem from scratch for a single directory where the drive is
Implementing a FAT Filesystem In this assignment, we will be creating a virtual filesystem from scratch for a single directory where the drive is implemented as memory in an array. You will be writing a console that can create, delete, rename files, as well as list drive usage in an array std::unique_ptr at (index). Store everything in fat_filesystem.cpp. In this assignment we encourage you to collaborate with other students. Data Structures and Starter Code All of these data structures are of fixed size, allowing you to std::memcpy them to/from an array. Constants // Size of the drive/array inline constexpr int kMaxDriveSize (1200); // Max filename length in the filesystem inline constexpr int kMaxFilename Size (16) ; // Max number of files in the directory inline constexpr int kMaxNumberFiles (5); // The number of bytes each block is on the drive inline constexpr int kBlockSize (30); // The number of elements in the File Allocation Table inline constexpr int kTableSize (30) ; // The end of file marker in the file allocation table inline constexpr int kEndOfFile (-1); struct FileEntry { }; std::array name { int starting block( 0); int size 0 }; double last_modified 0.0 }; ** }; This FileEntry encodes a single entry/row in the root directory array. If a file has an empty name, it does not exist in your virtual drive. RootDirectory std::array root_directory; The root directory stores all the information of the filesystem. Root directory: Name File A File B File C File D O 11 21 31 File A Start Size 10 20 22 30 12 30 -1 FileAllocation Table (4 blocks) std: :array fat table; 10 Allocation table 13 23 34 35 425 bytes 75 bytes 300 bytes 90 bytes File A 14 15 24 25 36 623 20 File B 37 Attributes 10/10/2014 @ 10:20 AM, Read only 09/03/2014 @ 11:59 PM 11/11/2013 @ 3:20 PM, Read only 11/12/2012 @ 9:15 AM 20 16 17 27 22 File F 38 File C 22 File C File D 30 33 18 28 39 File F 30 File E 19 29 -1 40 File E 33 40 -1 -1 FATFilesystem struct This will store all the major data and will be the main class. Everything (root folder, FAT folder, file data similar to the above diagram) should be stored in the drive array(a virtual drive you are creating). Its interface is below. Interface and Specification This should be a struct named FATFileSystem with the interface: You will need to load/save from the filesystem to the *_in_memory variables. Use std::memcpy for this. FATFilesystem (); Status createFile ( const std::string& filename unsigned int filesize, std::byte value) Status list Directory (); Status remove (const std::stringe filename) Status rename ( const std::string filename, const std::strings new_filename) Status print (const std::strings filename) Constructs the struct with an array of fixed size and initializes the file allocation table. Creates a file 'filename' with size 'filesize'. The file is filled with value 'value'. Prints on success: Success: File 'filename' with size 'filesize' and value 'value' has been created. Prints 'Error: string has non-alphabetic characters' when there is a non-alphabet character present. Prints 'Error: Array is full' and returns Status:: Error when the array is full. Prints 'Error: Max files reached and returns Status: Error when there is no more space for the file in the root directory. Prints the contents of the directory with sizes and dates (this should print the root directory contents). Prints 'Error: something went wrong and returns Status: Error when an error occurs.. Deletes the file 'filename from the drive. Prints 'Error: file does not exist' and returns Status:: Error when the file does not exist. Renames the file from 'filename' to 'new_filename' Prints 'Error: string has non-alphabetic characters' when there is a non-alphabet character present in either filenames. Prints 'Error: file does not exist' and returns Status: Error when the file does not exist. Prints the contents of file 'filename'. Prints "Error: file does not exist and returns Status:: Error Console You will need to write a console (for loop that accepts commands and calls the correct function above). These commands should mimic the unix-style commands 'rm' (delete), "Is' (list directory), 'mv' (rename), 'cat' (print), and a new 'create' (which is similar to fallocate -I in linux). > 18. > create test.txt 15 a > 18 total 203 bytes Name Start Block test.txt 10 > mv test.txt test2.txt > 18 >total 203 bytes Name Start Block test2.txt 10 >rm test2.txt > 18 > du 15/1024 bytes, 1.5% full > cat test.txt aaaaaaaaaaaaaaa Size 15 bytes Size 15 bytes Last Modified 10/10/2022 4:00:00PM Last Modified 10/10/2022 4:02:00PM #include #include #include #include #include #include enum class [[nodiscard]] Status { ok, invalid_input, index_error //todo add more if they're relevant }; template using Statusor = std::expected ; // Size of the drive/array inline constexpr int kMaxDrivesize (1200); // Max filename length in the filesystem inline constexpr int kMaxFilenameSize (16); // Max number of files in the directory inline constexpr int kMaxNumberFiles (5); // The number of bytes each block is on the drive inline constexpr int kBlockSize (30); // The number of elements in the File Allocation Table inline constexpr int kTableSize(30); // The end of file marker in the file allocation table inline constexpr int kEndofFile(-1); struct FileEntry { std:: array name{ }; int starting_block { }; int size(0); double last modified { 0.0 }; }; struct FATFilesystem { // This is the virtual drive we will be reading/writing to/from, and will store our filesystem std:: array drive; // Virtual memory versions of the root directory/FAT table, use memcpy to save/ load to/from the drive std:: array root_directory_in_memory; std:: array fat_table_in_memory; FATFilesystem() { // TODO } Status listDirectory() { // TODO 111 } return status::ok; status createFile( const std::string& filename, unsigned int filesize, std::byte value) { } } // TODO (void)filename; (void)filesize; (void)value; return status::ok; Status remove(const std::string& filename) { // TODO (void) filename; return status::ok; } status rename ( } const std::string& filename, const std::string& new_filename) { // TODO (void)filename; (void)new_filename; return status::ok; } Status print (const std::string& filename) { // TODO (void)filename; return status::ok; }; int main() { // e.g. to get size of root dir / FAT std::cout < < sizeof(std:: array ) < < " bytes" < < std::endl; std::cout < < sizeof(std:: array ) < < " bytes" < < std::endl; // TODO CONSOLE HERE return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To implement a FAT filesystem you can start by defining the necessary data structures and functions ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started