CSC 306 Assignment 4: A Floppy Disk Dumper Project due date: 11:59pm CST, 11/18/10 Statement Windows and Linux systems allow a programmer to open the floppy disk and read/write its contents as if it were a sequential file. In this project you will exploit this capability to experiment with raw I/O operations. Outline You need to do your solution in the Windows platform. The Virtual Floppy Disk software allows you to create a virtual floppy disk that operates exactly like a real floppy disk as far as the OS is concerned (http://www.freewarereview.info/2006-03/virtual_floppy_drive_- _floppy_disk_imaging_and_virtualization_part_ii.html ). Part I: Write the following functions in a file called disk.c: Disk PhysicalDisk(char letter): Creates the Physical Disk Abstraction for the particular disk (identified by the letter input parameter, A or B). o Step 1: Find the device (read as file) that has to be opened and open it for reading. On Windows the corresponding files one has to open are \\\\.\\A: for floppy drive A and \\\\.\\B: for floppy drive B (Note: Escape all backslashes to suit C string literals). o Step 2: Get the geometry of the floppy disk There are two options here (Hard but Sure Way) Read the boot record (first sector logical sector 0) and get the geometry information by reading the values there. (Easy but learn ioctl ) Read the device s parameters by using the DeviceIOControl() function in Windows which will populate a DISK_GEOMETRY (address of such a structure passed as parameter) struct with all the details about the disk. o Step 3: Get the geometry results of steps 1 and 2 and put them in the Disk structure and return. The Disk structure contains the device handle and details about the disk gathered from the system or directly from the boot sector. typedef struct disk_type *Disk; struct disk_type { HANDLE floppydisk; /* Handle: returned from CreateFile() */ DISK_GEOMETRY geometry; /* Find this struct description in <winioctl.h> */ } Void sectordump(disk thedisk, unsigned logicalsectornumber): Dumps the contents of the requested logical sector onto the screen. Note that logical sectors are sequentially numbered from 0 onwards. Logical sector 0 corresponds to the physical sector at surface 0, track 0, sector 1 on the disk. This incidentally is the boot sector aka boot record. The next logical sector (#1) contains the File Allocation Table (called FAT1). There is a
copy of this for backup purposes on logical sector #10 (Called FAT2). How do you read the sector s contents? Just like reading a file, however the logicalsectornumber passed as parameter must be converted to the correct offset to read from. This can be achieved by multiplying the logicalsectornumber with the bytes/sector obtained and stored in the Disk structure from calling PhysicalDisk() function above. Look at geometry fields for what the bytes/sector details is called in Windows. The output of the sectordump() function must be formatted to show 16 bytes of the dump per line. Optional function: BOOL sectorread(disk thedisk, unsigned logicalsectornumber, char *buffer): This is an optional function to divide your work in sectordump into two parts the reading and the formatting+printing. The sectorread() function does the reading so sectordump() calls it and then formats and prints the returned buffer. Part II: Write a driver program (driver.c) to drive the code written in disk.c. The driver will be run with three arguments: Argument 1: letter for the floppy drive (A/B) Argument 2: first sector the contents of which need to be dumped Argument 3: last sector the contents of which need to be dumped Here is an example run and output: Run: driver b 0 2 Output: Opening diskette in drive name: \\.\B: Drive B Media Type 3.5, 1.44MB, 512 Bytes/Sector Cylinders 80, Tracks/cylinder 2, Sectors/track 18 Logical Sector: #0 (Boot Sector): 0: eb 3c 90 56 46 44 32 2e 31 20 20 0 2 1 1 0 10: 2 e0 0 40 b f0 9 0 12 0 2 0 0 0 0 0 20: 0 0 0 0 0 0 29 cc e5 d5 31 4e 4f 20 4e 41 30: 4d 45 20 20 20 20 46 41 54 31 32 20 20 20 0 0 40: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 70: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 80: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
e0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1a0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1f0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 aa Logical Sector: #1 (FAT1): 0: f0 ff ff 3 40 0 5 60 0 7 80 0 9 a0 0 b 10: c0 0 d e0 0 f 0 1 11 20 1 13 40 1 15 60 20: 1 17 80 1 19 a0 1 1b c0 1 1d e0 1 1f 0 2 30: 21 20 2 23 40 2 25 60 2 27 80 2 29 a0 2 2b 40: c0 2 2d e0 2 2f 0 3 31 20 3 33 40 3 35 60 50: 3 37 80 3 39 a0 3 3b c0 3 3d e0 3 3f 0 4 60: 41 20 4 43 40 4 45 60 4 47 80 4 49 a0 4 4b 70: c0 4 4d e0 4 4f 0 5 51 20 5 53 40 5 55 60 80: 5 57 80 5 59 a0 5 5b c0 5 5d e0 5 5f 0 6 90: 61 20 6 63 40 6 65 60 6 67 80 6 69 a0 6 6b a0: c0 6 6d e0 6 6f 0 7 71 20 7 73 40 7 75 60 b0: 7 77 80 7 79 a0 7 7b c0 7 7d f0 ff 0 0 0 e0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1a0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Logical Sector: #2 0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 40: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 70: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 80: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 e0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1a0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Your project solution on Windows may be written in C or C++ using VC++ or any other IDE of your choice. If you use existing code skeletons from the internet, be sure to cite it appropriately. Grading Criteria:
The grader will use the following criteria: 20 Reads and parses arguments of command line 40 Displays the disk geometry correctly 15 Opens the correct device/file 25 Gets the geometry/details of the disk 40 Dumps the sectors as specified 20 Reads the sector contents correctly (on sector boundaries) 15 Formats and prints sector as specified 5 Identifies boot sector and FAT1, FAT2 correctly Submission: Submit a single zip file containing all the files that make up your project. No executables, only sources (.cpp,.h). Send as an email attachment to preetam.ghosh@usm.edu