Implementing a FAT Filesystem In this assignment, we will be creating a virtual filesystem from scratch...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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; 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;
Expert Answer:
Answer rating: 100% (QA)
To implement a FAT filesystem you can start by defining the necessary data structures and functions ... View the full answer
Related Book For
Operating Systems Design And Implementation
ISBN: 9780131429383
3rd Edition
Authors: Andrew Tanenbaum, Albert Woodhull
Posted Date:
Students also viewed these programming questions
-
Which devices support Microsoft Entra join with automatic MDM enrollment?
-
What does "variable declaration" mean? ( check all that apply )?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Prudence Corporation manufactures two products: X and Y. The company has 4,000 hours of machine time available and can sell no more than 800 units of product X. Other pertinent data follow. Which of...
-
Consider a smooth isentropic compression turn of 20°, as in Fig. P9.144. The Mach waves thus generated will form a converging fan. Sketch this fan as accurately as possible, using five equally...
-
Manning Inc., is the leading manufacturer of garage doors. Demand for residential garage door sales depends, of course, on the rate of new house building activity, which in turn depends on changes in...
-
A company is considering a new three-year expansion project that requires an initial fixed investment of \(\$ 1.8 \mathrm{MM}\). The fixed asset is depreciated based on the five-year class life in...
-
B. Cates, V. Elder, and S. Nguyen have capital balances of $50,000, $40,000, and $32,000, respectively. Their income ratios are 5 : 3 : 2. Nguyen withdraws from the partnership under each of the...
-
What is the definition of abnormal psychology ? What diagnoses come to mind when defining abnormal psychology?
-
Create a concept map that depicts your assumptions and findings of the theory-practice gap. You are a staff nurse working in an intensive care unit and assigned to care for a 75-year-old African...
-
Two wires of equal length, one of aluminium and the other of copper have the same resistance. Which of the two wires is lighter? Hence explain why aluminium wires are preferred for overhead power...
-
A partnership has total equity of $464,000. Partnership equity consists of Green, Capital, $324,000, and Tan, Capital, $140,000. Net income and loss is shared in a ratio of 85% to Green and 15% to...
-
S Last month when Holiday Creations, Incorporated, sold 37,000 units, total sales were $148,000, total variable expenses were $111,000, and fixed expenses were $36,500. Required: 1. What is the...
-
Example: A high-tech consumer product manufacturer in Southeast Wisconsin (Milwaukee) is investigating outsourcing possibilities for an important electronic component used in their final product. The...
-
JP Morgan Bank classifies its investments into the following categories: (a) Trading bond investments. (b) Available-for-Sale bond investments, (c) Held-to-Maturity bond investments (d) Equity...
-
Complete a tax return for Stewart L. Benjamin. Stewart is unmarried, has no dependents, and works as a retail manager; his W-2 is below. Using the1099s and the transaction description which follow,...
-
The spot rate between the Mexican peso (MXN)and the US Dollar(USD)in New York is MXN 20.8741/USD and the 6-month futures rate is MXN 20.9944/USD. If US interest rates are 5% per annum, what is the...
-
Find the image of x = k = const under w = 1/z. Use formulas similar to those in Example 1. y| y = 0 -21 -2 -1 -1, /1 12 T -1 -1 y= -2 x =0
-
Write a shell that is similar to Fig. 1-10 but contains enough code that it actually works so you can test it. You might also add some features such as redirection of input and output, pipes, and...
-
An operating system only supports a single directory but allows that directory to have arbitrarily many files with arbitrarily long file names. Can something approximating a hierarchical file system...
-
Why is the process table needed in a timesharing system? Is it also needed in personal computer systems in which only one process exists, that process taking over the entire machine until it is...
-
A prototype can be ___________. (a) Complete system with partial requirements (b) Working model (c) Full-fledged system (d) All of these
-
_____________ is also used as requirement finding and feasibility testing tool. (a) Prototype (b) Reports (c) System (d) Procedure
-
Which of the following systems development approach is adopted if information requirements are not well defined? (a) SDLC (b) Prototype (c) Structured approach (d) Agile
Study smarter with the SolutionInn App