You have to implement a file storage system (virtual hard disk) that should have the following specifications. On the execution of your code your console should display the following options to the user.
1. Create a new file.
2. List & view existing files.
3. Copy file from windows (*.txt).
4. Copy file to windows (*.txt).
5. Modify.
6. Delete.
7. Defragmentation (Bonus Feature)
System Initialization
At the initialization of file system, a 10 MB file should be initialized. Your file should be divided into 3 parts.
Figure 1: File_system
First portion (1MB) of your file “File_system” should be reserved for the file names and the starting address of the data in the file. It should be subdivided into sub blocks, each of capacity …show more content…
After copying the file from windows to File_system following changes should occur in your File_system .
Figure 4: Changes in your File_system that takes place when an existing file is copied from windows
Copy File to windows
When a user wants to copy a file from File_system to windows he will select this option. User will enter the file name he wants to copy and the file gets copied with the name same as that in the File_system. For example, user wants to copy “New.txt” to windows. A new file will be created as follows while the File_system remains unchanged.
Figure 5: File copied from File_system to windows.
Modify File
The user should also be given an option to modify existing files in the File_system. The only modification user can make in any of the files is concatenation of the data at the end of file. For example, if the user selects “File1.txt” to modify your program should prompt for the data he wants to append in the file. After the user enters the data it gets appended at the end of already existing data. There may also be the case that after modification the data of file exceeds 1024B. A continuation block should be added by allocating a new memory block from second portion of File_system. Let the data entered by user be “this is my extension file”. This data will be appended in “File1.txt” and the following changes will …show more content…
If the user wants to delete “File1.txt” from the File_System the following steps will occur:
Delete the file name from first block of File_system.
Remove the data placed in the data place of “File1.txt”.
Add the de allocated blocks in second block (block of empty locations) of File_system.
Figure 7: Changes after deleting a file “File1.txt” from File_system
Defragmentation
Considering the above scenario, deletion of “File1.txt” resulted in a vacant slot at start and a vacant slot at end. After many such deletions your File_system may have many vacant blocks in between the allocated blocks which may results in more computation time. This issue can be resolved through defragmentation. Once the File_system is subjected to defragmentation all the occupied blocks will arrange at consecutive locations leaving behind the empty blocks together.
Figure 8: File_system before defragmentation
Figure 9: File_system after