Defrag-O-Matic Assignment | Homework Help Websites

CMPE2300 – Lab01 – Defrag-o-matic

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

In this lab you will create a simulator to implement a file system defragmentation. Prior to

SSDs, file systems benefited from ensuring files that were comprised of multiple disk

partition units were allocated and adjacent on disk. This ensured minimum head

movement for read/write of specific files.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Our goal is to read in a text file formatted as one file allocation unit per row with a data

component indicating the file name, a sequence number indicating part N ( of M ) units,

and a next value indicating where the next unit resides. Once loaded and displayed the

simulator will allow a basic defragmentation to be done, attempting to group files into

adjacent allocation blocks.

Program Specification

Your project will require use of the CDrawer.

You will need to define a structure to represent file allocation units, comprised of :

• a string – representing the filename ( it will be one character for our simulation )

• an integer – representing the sequence number of this allocation unit

• an integer – representing the allocation unit of the next part of the file.

professional writing services near me

Assumptions :

A next value of -1 indicates that this allocation unit is empty

A next value of -2 indicates that this is the last allocation unit of this file

Any file system load will always have > 0 empty units

Your UI will have 3 buttons :

[Load FileSystem]

[Verify FileSystem]

[Defragment] / Toggling to disable defragmentation

And a listbox for status output – population should always use insert so newest additions

are first.

Part I – Load FileSystem

Your application will be allowed to create class level members for the following :

• List of File Allocation Units ( structure )

• CDrawer

• integer representing CDrawer File Allocation Scale ( not CDrawer scale )

• constant integer representing the maximum width for the CDrawer in pixels = 1000

Bind your [Load FileSystem] click event to a method in your form constructor.

[Load FileSystem]

Dynamically create an OpenFileDialog, and using System.IO.Path.GetFullPath and the

appropriate Environment variable, set the Initial directory to the root source ( this will allow

easy loading of the test files in your project ). Using System.IO.File.ReadAllLines(), read the

user selected file in.

For each line read, you may use split() to separate the 3 expected elements to be

processed. Process as required to make and add a structure entry to your List for each.

Upon completion, add a status line in the form : “Load FileSystem: Loaded N units”

Now that the load is complete, it needs to be displayed in the CDrawer. We want our

displayed grid to be square – in number ( ie. 6 x 6 ). Given the load number, determine the

smallest dimension that can be used. The “scale” is the file unit cell height, it will be 4

times wider than tall to fit our output requirements. Given the fixed CDrawer width,

determine the “scale”, and close any existing CDrawer before allocating a new CDrawer of

our calculated dimensions.

To actually display the file units, create a some new helper methods :

MakeColors() – returns nothing and accepts nothing. It will be invoked from the

constructor and will populate a form member List<Color> with a new list then fill the list

with colors derived from r, g and b values of 64, 128, 192 ( notice the pattern – a triple

nested loop is required ). The list will now be comprised of ?? colors, matching our

alphabet filename needs.

RenderUnits() – returns nothing, accepting a List of file units, a CDrawer and the file unit

height. Clear() the CDrawer, and iterate through all the file units. For each, construct a

Rectangle object with the appropriate X, Y coordinates ( Grid work ? ), a width 4 times the

height. If the file unit is empty, fill the rectangle with gray. Otherwise, use the letter as the

offset ( ie. a is 0, b is 1,.. z = 25 ) fill the rectangle with the indexed color from our colors list.

Then using the same Rectangle, use AddText to populate the rectangle with file unit’s

information in the form :

file_name:sequence_number:next_value, ie. h:3:34

Remember to render your CDrawer.

Now include RenderUnits as the last thing in your load function to see your filesystem.

Part II – Verify File System

Just because our file system loaded it does not mean it is valid. We need to validate the

loaded system to ensure all file units ( and supposed empty space ) are error free. This

step is of your own design, with these basic requirements :

• Every file unit will start having a sequence number of 0. A file unit chain must end

with a next value of -2. A file may consist of a single file unit ( sequence = 0 and next

of -2 ).

• Verification requires that every file unit chain is in sequence and terminates

correctly.

• Verification may discontinue on the first error found – as many possible errors could

potentially create an avalanche of cascading and compounding errors.

• Any error found should result in a status addition in the following form :

Validation:Error:error_condition with appropriate values.

Error conditions would include, but not be limited to :

• File_name : termination missing

• File_name : out of sequence

• File_name : start unit missing

Your instructor will discuss possible approaches.

Part III – Defragmentation

We need some helper functions to implement defragmentation.

FirstEmpty() – returns an integer representing the found empty index, accepts a list of file

units and a bool representing if the search should start halfway through the list – set a

default value of false. This method is used to find an available spot to move an existing file

unit for defragmentation. Depending on the bool flag, start searching the list returning the

index of the first empty spot encountered in the supplied list. Starting halfway must still

cycle around through to the start looking for an empty spot. Only a single loop and

remembering our assumptions is required.

MoveUnit() – returns void, accepts a list of file units, a list index to move and a list index to

move the file unit to. In order to move a file unit, there may be an existing file unit that has

a next value referencing the move location. This unit must be modified in order to maintain

order in the move. Therefore, using the file name and move index determine ( if any ) prior

unit exists – save this index ( or -1 for no prior unit found ).

Now perform the move – the order is critical here – copy the unit to be moved to the new

empty location, modify ( if required ) the prior unit, lastly set the move index unit to empty.

Why is this important if this were real defragmentation ?

NeedDefrag() – returns an index indicating a unit that should be defragged. It accepts a

list of file units. We will use a “lazy” evaluation of whether defragmentation is required. It

involves 2 distinct passes through the list.

The first pass determines if we have a “starter” unit ( seq = ? ) and if the next unit is not next

in line. If so, we want this unit defragged, return this index.

The second pass, if the first pass found nothing, determine if a unit is found where the next

unit is not the next in line. If so, we want to this unit defragged, return the index.

This method is biased to try to defragment units which are the start of a file unit chain.

Thread method Defrag(), accepts an object ( the list of units to defragment ) and returns

nothing. This method will be used as a Thread target, created and started when the user

clicks the Defragmentation button. The thread reference should be created as a form

member and will be used by the thread to monitor for termination.

Repeat forever while the thread reference is valid :

Render your file system, have short sleep ( 25ms for checkoff, 500ms or more for debug )

Invoke your NeedDefrag() method saving the returned unit index. If no units need debug

break your loop, set your thread reference to null and let the method complete.

Otherwise we have a unit whose next adjacent unit is wrong. There is a special case here,

if the last unit is indicated, we can’t move ANY adjacent units. So, if the unit indicated is the

last node and is not the last node in the file chain, invoke MoveUnit with the unit index and

the index returned by FirstEmpty() retrieving the true first empty index. If this special case

occurred, this pass is complete, continue.

Normal processing is to determine the swap index for our move of the adjacent next unit

that is out of place. Invoke FirstEmpty() with a midway start saving the returned index as

our swap index. Now we have a unit to move and a place to move it to, but we are moving

the next unit to make room for the unit that belongs there !

MoveUnit() the adjacent unit to our swap index, ie. move it out of the way.

MoveUnit() the unit that belongs next, to the next index spot. ( use next value )

The cycle is complete, one down, many to go. Prior to exiting your thread method, ensure

you set the thread member to null, indicating the thread is complete.

You will need to update the main UI as to the progress made by Defrag(). Determine an

appropriate delegate type, and using Invoke() ( not Dispatcher.Invoke() ), invoke a string

message back to the main UI thread to update the status listbox for each MoveUnit

operation in the form “Defrag: Moved [N] to [M]”.

To finish wiring up the UI, implement a toggle action on the button so it toggles between

[Defragment] and [Cancel Defrag], using the thread member as both the indicator for the

button text and the flag for your thread termination. Your thread should Invoke a message

back prior to exiting in the form “Defrag:Thread terminated”

file:///C:/Users/user/Downloads/CourseOutlineCMPE2300-2018.pdf

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Homework Writing Services
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Education
GOOD
Customer 463813, April 20th, 2023
Human Resources Management (HRM)
Thank you .
Customer 464767, February 5th, 2024
Home Repair & Home Maintenance
Good job!
Customer 463337, November 21st, 2022
SEO
A job well done.
Customer 463679, May 13th, 2023
Computer science
Paper was extremely because support team did not read my request, causing it to be extremely late. I should receive at some type of refund because that one is not on me...
Customer 452515, April 19th, 2020
Nursing
Excellent work. Had a few issues but tutor stayed in contact and produced a succinct and quality paper.
Customer 453939, April 26th, 2020
Healthcare & Medical
Good work
Customer 463469, October 22nd, 2022
Military
good job
Customer 456821, October 8th, 2022
Business and administrative studies
Good work.
Customer 458115, May 10th, 2022
English 101
Good. However, always manually proofread,
Customer 460547, April 25th, 2022
Business and administrative studies
Excellent
Customer 460073, July 2nd, 2022
Business Studies
Good Job
Customer 453413, April 27th, 2020
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat