Question
i need code in c++ You have to implement a file storage system (virtual hard disk) that should have the following specifications. On the execution
i need code in c++
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.
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 500B. In other words, each sub block in the first block (1 MB) of the file should have a capacity to store file name and starting address which should not exceed 500B.
Second portion (1MB) of your file File_system should be reserved for listing the available empty (vacant) blocks in the third portion.
Third portion (8MB) of your file File_system should be reserved for the data to be written in the files listed in first portion of your File_system.
Create new file
If the user selects this option, console will prompt the user for
The name of the text file. After the user enters name of the file, your program should check whether the file with this name already exist. For example, from the above example if user wants to create a file with File1.txt a message should be displayed the file already exists.
The data he wants to write in the text file. User can enter data of unspecified length (even if greater than a block size i.e. 1024B) your program should cater with this by allocating another block from the empty blocks available in second portion of the File_system.
After taking the data from the user, the program should
Look for the available empty space (from second portion) and write the data at that location.
Remove that address from the second block of File_system i.e. block of available slots.
If the file new file comprises of more than one 1024 MB blocks then each block should contain the address of the next continuation block. Data in the file should be delimited by any delimiting character that indicates end of file for that particular file. For example in figure 2 two files are saved in the file system named File1 and File2 both having data size less than 1024B, thus a single block of 1024B is allocated to each with a /0 at end that indicates end of file. Suppose the new file comprises of data more than 1024B, then another empty block should be allocated from the second block of
File_system.Each continuation block of the same file should be linked by adding the address of next block (if any) in the previous block.
Name of the new file and the address location should be updated in the block1 of File_system.
List & view existing files
If the user selects this option, all the names of the files placed in the file system should be displayed and user should be prompt for the file name he wants to be displayed. In above scenario, on selecting this option following list should be displayed:
1. File1
2. File2
3. New
If the user selects New the console should display the data in the file after reading from the location.i.e. My new file data exceeds in size.
Copy File from Windows
This option facilitates the user to copy any file (*.txt) placed on hard disk to this File_system. The user should specify the file name he wants to copy along with the path and all the data placed in the file gets copied in the file system. Suppose user wants to copy a file copy.txt with content this is copied data
placed at somewhere in harddisk. After copying the file from windows to File_system following changes should occur in your File_system .
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.
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 occur.
Delete
User can also delete any of the file from File_system by giving the file name. 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.
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.
Note:
1. Your program, when executed should load all data from file to memory (RAM). Choose a data structure optimum for above listed operations. All changes made during execution will be updated in harddisk at the time of termination of program.
2. You have to follow the specifications and features of the file_system mentioned above.
3. Implementation of Fragmentation will add bonus marks to your final project marks.
4. To avoid complexity file_system is restricted to (*.txt) files only.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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