SlideShare a Scribd company logo
1 of 9
CMPE2300 – Lab01 - Defrag-o-matic
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.
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.
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”
Mark completion rubric.
Part I : Basic UI, Load and Render to spec 30
Part II : Verify filesystem, functional, correctly identifies test
files 30
Part III : Defragmentation, functional for supplied test files 40
Tips
Do not code more than a few lines before testing / debugging.
Do ask questions about functionality, operation, assumptions on
your part.
CMPE2300 – Lab01 - Defrag-o-maticProgram SpecificationTips

More Related Content

Similar to CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx

Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdffeetshoemart
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdfMemeMiner
 
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdfReaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdffashionbigchennai
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentalssirmanohar
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfrajeshjangid1865
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptxDwijBaxi
 
You must implement the following functions- Name the functions exactly.docx
You must implement the following functions- Name the functions exactly.docxYou must implement the following functions- Name the functions exactly.docx
You must implement the following functions- Name the functions exactly.docxSebastian6SWSlaterb
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfAxmedcarb
 
Stacks
StacksStacks
StacksAcad
 
fileop report
fileop reportfileop report
fileop reportJason Lu
 
C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaManoj Kumar kothagulla
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfaromalcom
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysBlue Elephant Consulting
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixNovita Sari
 

Similar to CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx (20)

Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdf
 
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdfReaction StatisticsBackgroundWhen collecting experimental data f.pdf
Reaction StatisticsBackgroundWhen collecting experimental data f.pdf
 
Linux basics
Linux basicsLinux basics
Linux basics
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Educational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdfEducational Objectives After successfully completing this assignmen.pdf
Educational Objectives After successfully completing this assignmen.pdf
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
You must implement the following functions- Name the functions exactly.docx
You must implement the following functions- Name the functions exactly.docxYou must implement the following functions- Name the functions exactly.docx
You must implement the following functions- Name the functions exactly.docx
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
Tech talk
Tech talkTech talk
Tech talk
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Stacks
StacksStacks
Stacks
 
fileop report
fileop reportfileop report
fileop report
 
C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kella
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
 
Vb.net iv
Vb.net ivVb.net iv
Vb.net iv
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & Arrays
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/Unix
 

More from mary772

Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docx
Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docxCoding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docx
Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docxmary772
 
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docx
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docxCNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docx
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docxmary772
 
Cognitive and Language Development Milestones Picture Book[WLO .docx
Cognitive and Language Development Milestones Picture Book[WLO .docxCognitive and Language Development Milestones Picture Book[WLO .docx
Cognitive and Language Development Milestones Picture Book[WLO .docxmary772
 
Codes of (un)dress and gender constructs from the Greek to t.docx
Codes of (un)dress and gender constructs from the Greek to t.docxCodes of (un)dress and gender constructs from the Greek to t.docx
Codes of (un)dress and gender constructs from the Greek to t.docxmary772
 
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docxCoding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docxmary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxmary772
 
CoevolutionOver the ages, many species have become irremediably .docx
CoevolutionOver the ages, many species have become irremediably .docxCoevolutionOver the ages, many species have become irremediably .docx
CoevolutionOver the ages, many species have become irremediably .docxmary772
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxmary772
 
Codes of Ethics Guides Not Prescriptions A set of rules and di.docx
Codes of Ethics Guides Not Prescriptions A set of rules and di.docxCodes of Ethics Guides Not Prescriptions A set of rules and di.docx
Codes of Ethics Guides Not Prescriptions A set of rules and di.docxmary772
 
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docx
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docxCodecademy Monetizing a Movement 815-093 815-093 Codecademy.docx
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docxmary772
 
Code switching involves using 1 language or nonstandard versions of .docx
Code switching involves using 1 language or nonstandard versions of .docxCode switching involves using 1 language or nonstandard versions of .docx
Code switching involves using 1 language or nonstandard versions of .docxmary772
 
Code of Ethics for the Nutrition and Dietetics Pr.docx
Code of Ethics  for the Nutrition and Dietetics Pr.docxCode of Ethics  for the Nutrition and Dietetics Pr.docx
Code of Ethics for the Nutrition and Dietetics Pr.docxmary772
 
Code of Ethics for Engineers 4. Engineers shall act .docx
Code of Ethics for Engineers 4. Engineers shall act .docxCode of Ethics for Engineers 4. Engineers shall act .docx
Code of Ethics for Engineers 4. Engineers shall act .docxmary772
 
Coder Name Rebecca Oquendo .docx
Coder Name  Rebecca Oquendo                                    .docxCoder Name  Rebecca Oquendo                                    .docx
Coder Name Rebecca Oquendo .docxmary772
 
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docx
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docxCodes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docx
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docxmary772
 
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docx
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docxCNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docx
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docxmary772
 
Code#RE00200012002020MN2DGHEType of Service.docx
Code#RE00200012002020MN2DGHEType of Service.docxCode#RE00200012002020MN2DGHEType of Service.docx
Code#RE00200012002020MN2DGHEType of Service.docxmary772
 
CODE OF ETHICSReview the following case study and address the qu.docx
CODE OF ETHICSReview the following case study and address the qu.docxCODE OF ETHICSReview the following case study and address the qu.docx
CODE OF ETHICSReview the following case study and address the qu.docxmary772
 
cocaine, conspiracy theories and the cia in central america by Craig.docx
cocaine, conspiracy theories and the cia in central america by Craig.docxcocaine, conspiracy theories and the cia in central america by Craig.docx
cocaine, conspiracy theories and the cia in central america by Craig.docxmary772
 
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docx
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docxCode of EthicsThe Code of Ethical Conduct and Statement of Com.docx
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docxmary772
 

More from mary772 (20)

Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docx
Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docxCoding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docx
Coding NotesImproving Diagnosis By Jacquie zegan, CCS, w.docx
 
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docx
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docxCNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docx
CNL-521 Topic 3 Vargas Case StudyBob and Elizabeth arrive.docx
 
Cognitive and Language Development Milestones Picture Book[WLO .docx
Cognitive and Language Development Milestones Picture Book[WLO .docxCognitive and Language Development Milestones Picture Book[WLO .docx
Cognitive and Language Development Milestones Picture Book[WLO .docx
 
Codes of (un)dress and gender constructs from the Greek to t.docx
Codes of (un)dress and gender constructs from the Greek to t.docxCodes of (un)dress and gender constructs from the Greek to t.docx
Codes of (un)dress and gender constructs from the Greek to t.docx
 
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docxCoding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CoevolutionOver the ages, many species have become irremediably .docx
CoevolutionOver the ages, many species have become irremediably .docxCoevolutionOver the ages, many species have become irremediably .docx
CoevolutionOver the ages, many species have become irremediably .docx
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
 
Codes of Ethics Guides Not Prescriptions A set of rules and di.docx
Codes of Ethics Guides Not Prescriptions A set of rules and di.docxCodes of Ethics Guides Not Prescriptions A set of rules and di.docx
Codes of Ethics Guides Not Prescriptions A set of rules and di.docx
 
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docx
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docxCodecademy Monetizing a Movement 815-093 815-093 Codecademy.docx
Codecademy Monetizing a Movement 815-093 815-093 Codecademy.docx
 
Code switching involves using 1 language or nonstandard versions of .docx
Code switching involves using 1 language or nonstandard versions of .docxCode switching involves using 1 language or nonstandard versions of .docx
Code switching involves using 1 language or nonstandard versions of .docx
 
Code of Ethics for the Nutrition and Dietetics Pr.docx
Code of Ethics  for the Nutrition and Dietetics Pr.docxCode of Ethics  for the Nutrition and Dietetics Pr.docx
Code of Ethics for the Nutrition and Dietetics Pr.docx
 
Code of Ethics for Engineers 4. Engineers shall act .docx
Code of Ethics for Engineers 4. Engineers shall act .docxCode of Ethics for Engineers 4. Engineers shall act .docx
Code of Ethics for Engineers 4. Engineers shall act .docx
 
Coder Name Rebecca Oquendo .docx
Coder Name  Rebecca Oquendo                                    .docxCoder Name  Rebecca Oquendo                                    .docx
Coder Name Rebecca Oquendo .docx
 
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docx
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docxCodes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docx
Codes of Ethical Conduct A Bottom-Up ApproachRonald Paul .docx
 
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docx
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docxCNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docx
CNL-530 Topic 2 Sexual Response Cycle ChartMasters and John.docx
 
Code#RE00200012002020MN2DGHEType of Service.docx
Code#RE00200012002020MN2DGHEType of Service.docxCode#RE00200012002020MN2DGHEType of Service.docx
Code#RE00200012002020MN2DGHEType of Service.docx
 
CODE OF ETHICSReview the following case study and address the qu.docx
CODE OF ETHICSReview the following case study and address the qu.docxCODE OF ETHICSReview the following case study and address the qu.docx
CODE OF ETHICSReview the following case study and address the qu.docx
 
cocaine, conspiracy theories and the cia in central america by Craig.docx
cocaine, conspiracy theories and the cia in central america by Craig.docxcocaine, conspiracy theories and the cia in central america by Craig.docx
cocaine, conspiracy theories and the cia in central america by Craig.docx
 
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docx
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docxCode of EthicsThe Code of Ethical Conduct and Statement of Com.docx
Code of EthicsThe Code of Ethical Conduct and Statement of Com.docx
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx

  • 1. CMPE2300 – Lab01 - Defrag-o-matic 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. 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
  • 2. • an integer - representing the allocation unit of the next part of the file. 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
  • 3. 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
  • 4. 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
  • 5. 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.
  • 6. 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
  • 7. 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
  • 8. 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” Mark completion rubric. Part I : Basic UI, Load and Render to spec 30 Part II : Verify filesystem, functional, correctly identifies test files 30 Part III : Defragmentation, functional for supplied test files 40 Tips
  • 9. Do not code more than a few lines before testing / debugging. Do ask questions about functionality, operation, assumptions on your part. CMPE2300 – Lab01 - Defrag-o-maticProgram SpecificationTips