Question: In java. In this assignment you will test the efficacy of two disk - allocation schemes: Contiguous allocation and indexed allocation. Your program takes as
In java.
In this assignment you will test the efficacy of two diskallocation schemes: Contiguous allocation and indexed allocation. Your program takes as input a file diskdat containing a list of requests to add, read, and delete files. The first line of the input file, disk.dat, contains a single integer, the number of blocks, b on a simulated disk drive the blocks are numbered to b Subsequent lines are requests to either add a new file of a given size, to delete a previously added file, or to print the current contents of the simulated drive.Each "add" request is of the form: add "nameString" sizeWhere size is an integer, equal to the number of blocks needed by the file named nameString which may contain space characters, by the way If there is sufficient space to hold the file, it should be allocated by adding the corresponding entry to the drive's directory which your program will have to maintain, of course If there is insufficient space, print an error message, and do not alter the directory.Each"del" request is of the form: del "nameString"Where nameString is the name of a file to be removed from the simulated drive. If no such file exists perhaps because there was insufficient space to add it earlier print an error message to that effect. Otherwise, delete the file, freeing the blocks it occupies for use by a subsequent add request.Each "read" request is of the form: read "nameString"Where nameString is the name of a file to be read from the simulated drive. Count the number of head moves necessary to accomplish the read. One move is necessary to get to the first block of the file. Which will be a FAT block for the indexing scheme. Each subsequent block will require another head move, unless the blocks are contiguous. Ie the second block has an index exactly one larger than the first.Each "print" request is for the form: printThis should print the current drive contents in the following format where blockij corresponds to the jth block belonging to file number i: filename block block block blockN filename block block block blockN The first part of the output is a numbered list, enumerating the files, and indicating the blocks occupied by each file. The blocks should be printed in the order in which they appear within the fileThe second part of the output is a tabular representation of the simulated hard disk. Each line row of the table represents the status of blocks of the disk. The first line represents the status of the blocks number to The second corresponds to blocks to and so onEach element of the table represents one block of the disk. The elements are either an indicating that the block is unallocated, or an integer, i indicating that this block is being used to store a portion of file number i corresponding to the ith entry in the numbered list, above.Here is a sample input file, and the corresponding output file.Details of the allocation methodsDefine a hole to be a maximal contiguous sequence of unallocated blocks. Maximal means that the block, if any, immediately preceding and following the hole must be allocated. The number of blocks comprising a hole is the size of the hole.For contiguous allocation, use a bestfit methodology. For a file consisting of n blocks, allocate n contiguous blocks within the smallest hole whose size is greater than or equal to n The allocated blocks should be the smallest numbered blocks in the hole. Ie allocate blocks from the top, within each hole.For indexed allocation, assume that you can store the addresses indexes really of blocks in a FAT block. If the th address is used, then, it must be the address of another FAT block. For example, if a file required blocks to hold its content, it would actually require blocks to store the file: for data, plus FAT blocks data block addresses in the first two FAT blocks, and in the lastIn allocating blocks, always allocate "topdown": the first block which will be a FAT block will be the lowest numbered free block.Counting Head MovesYou are required to count the number of head moves the disk head of the simulated hard disk would have to make to satisfy the file access commands specified in disk.dat. For simplicity, you need only keep track of head moves for the read operation.Notes:You'll have to maintain a free list of some kind. The book outlines a couple of methods, including bit vectors, tables, and linked lists. I leave the design of the free list up to you.OUTPUT:Run your simulation on the input file, disk.dat, first using contiguous allocation. Then run the simulation on the same input, using indexed allocation. After each run, print the number of head moves required during the simulation, and the number of files that could not be allocated because there was insufficient free space. Were primarily interested in the problem of external fragmentation, here.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
