Recent Question/Assignment
The aim of this assignment is to simulate a write operation on the sectors of
a hard drive.
A simplified definition of a sector, as obtained from a manufacturer's
data sheet, is as follows:
bytes name Values and purpose
----- ------------- ---------------------------------------------------
13 ID START Values: 0x00; start of sector id section
1 ID SYNC Value: 0xA5; tells controller that data follows.
2 TRACK NUMBER A 16-bit value that defines the track number.
1 SECTOR NUMBER An 8-bit value that defines the sector number.
13 DATA START Values: 0x00; start of data section.
1 DATA SYNC Value: 0xA5; tells controller that data follows.
64 DATA Initial values: 0xF3; the area for user data.
Will be overwritten with actual data.
2 ERC 16-bit Error Check to verify the user data.
Written during format operation. Recalculated and
rewritten after every data write operation.
It is advisable to declare the fields as unsigned integers or chars as
appropriate, and use bit fields wherever necessary.
A small text file is attached; this text requires three sectors for
storage. Input is terminated when the hash character # is read. You should
use I/O redirection to read the data into the program in the usual way
using 'scanf': to read input from file words.txt (instead of from the
keyboard) enter the command
./a.exe words.txt
(assuming your compiled program is called a.exe). I/O redirection forces
the program to read the data from the words.txt file instead of from
the keyboard. You use the scanf function in the usual manner to get the
input, as if the data was read from the keyboard.
Your program should do the following:
- define an appropriate data structure for a sector, using
methods discussed during the lecture. Declare three sectors. Use 31 as
the track number and 1, 2 , 3 as the sector numbers; Access the sectors
using a pointer.
- format the sectors, by initialising the various fields of the
sectors with appropriate values as shown above, as well as calculating
the error code;
- reading appropriate amounts of data from the text file,
writing it into the sector, and calculating and writing the error code;
- dumping the sector contents to the screen in a neat format.
This shows that everthing was written properly.
The algorithm for calculating the error check is as follows ('old' and
'new' are integers):
old = 0
for (all bytes in the data area) do
new = (old*23 + byte) mod 65536
old = new
The final result is a 16-bit variable whose value is highly dependent upon the
sequence of bytes that was used.
Note that you have to put the following lines at the start of the
program:
#include stdio.h
#include string.h
Your program should make generous use of comments to make sure that
everything is explained clearly. Include brief documentation outlining the
stucture of the code, and testing results.
Your submission should consist of a single pdf file on Blackboard, in
the format detailed at the end of your lecture notes handout.
doubledecker
morality
precondition
whereas
elephant
class
royale
ancient
Vesuvian
dart
coin
famous
distant
butcher
slanting
vixen
brewery
vision
#