Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a code for it in C++ using linked list. Write a program to simulate managing files on disk. Define the disk as a

Please write a code for it in C++ using linked list.

Write a program to simulate managing files on disk. Define the disk as a one-dimensional array disk of size numOfSectors * sizeOfSector, where sizeOfSector indicates the number of characters stored in a one sector. (For the sake of debugging, make it a very small number.) A pool of available sectors is kept in a linked list sectors of three-field structures: two fields to indicate ranges of available sectors and one next field. Files are kept in a linked list files of fours-field structures: file name, the number of characters in the file, a pointer to a linked list of sectors where the contents of the file can be found, and the next field. a) In the first part, implement functions to save and delete files. Saving files requires claiming a sufficient number of sectors from pool, if available, The sectors may not be contiguous, so the linked list assigned to the file may contain several nodes. Then the contents of the file have to be written to the sectors assigned to the file. Deletion of a file only requires removing the nodes corresponding with this file (one from files and the rest from its own linked list of sectors) and transferring the sectors assigned to this file back to pool. No changes are made in disk. b) File fragmentation slows down file retrieval. In the ideal situation, one cluster of sectors is assigned to one file. However, after many operations with files, it may not be possible. Extend the program to include a function together() to transfer files to contiguous sctors, that is, to create a situation illustrated in the attached figure. Fragmented files file1 and file2 occupy only one cluster of sectors after together() is finished. However, particular care should be taken not to overwrite sectors occupied by other files. For example, file1 requires eight sectors; five sectors are free at the beginning of pool, but sectors 5 and 6 are occupied by file2. Therefore, a file f occupying such sectors has to be located first by scanning files. The contents of these sectors must be transferred to unoccupied positions, which requires updating the sectors belonging to f in the linked list; only then can the released sectors be utilized. One way of accomplishing this is by copying from the area into which one file is copied chunks of sectors of another file into an area of the disk large enough to accommodate these chunks. In the example in the figure, contents of file1 are first copied to sectors 0 through 4, and then copying is temporarily suspended because sector 5 is occupied. Thus, contents of sectors 5 and t are moved to sector 12 and 14, and the copying of file1 is resumed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions