CS 635 PROJECT 1 Due Date: 9pm Friday 03/18/2005 The purpose of this project is to gain familiarity with designing a device-driver for Linux which involves interfacing with actual hardware, and simultaneously to create a useful tool for our future study of Linux filesystems. PROJECT STATEMENT Write an LKM (Loadable Kernel Module) named 'hd.c' for Linux kernel version 2.6.10 which implements a character-mode device-driver that will afford "safe" access to the hard disk inside our classroom workstations. (The machines in our Fifth Floor CS Labs also have identically formatted hard drives, available for your use outside of our class meeting times.) It should be possible, using the '/dev/hd' device special file (and your device-driver), for an application program to 'read' an arbitrary number of bytes from any valid location on the disk's surface, and also 'write' an arbitrary number of bytes to any location within the disk's currently unused 'minix' partition. (Any attempt by user software to modify areas of the disk which lie outside that 'minix' partition should fail with an 'EFAULT' code.) To implement these two requirements, your driver has to determine the hard disk's storage capacity (by using the IDENTIFY_DEVICE command during module initialization) as well as the starting and ending locations of the 'minix' partition (by reading the Master Boot Record to obtain the Partition Table information); and in additon you will need to implement an 'lseek()' function as one of the device-driver's 'methods'. As a demonstration that your device-driver is able to perform these read/write/seek operations, you should write a short application program (named 'hddemo.cpp') which will (1) open the '/dev/hd' file, (2) seek to the end-of-file to determine the disk's storage-capacity and print out a message that reports the device's size (in bytes) using both hexadecimal and decimal formats, (3) read sector 0 (i.e., the Master Boot Record) to obtain and display its Partition Table information (hexadecimal format), (4) read the initial 'minix' sector and show its contents (hexadecimal), and (5) write your own name at the very end of the final 'minix' sector, without modifying any earlier bytes in that sector, then read back every byte in that sector and show their values (both hexadecimal and ascii). WHAT TO SUBMIT Copy your 'hd.c' source file and your compiled 'hd.ko' kernel object file to the your '/submit' directory where your Instructor can access it for testing and grading; also copy your 'hddemo.cpp' source file and the compiled application 'hddemo' in your '/submit' directory; finally, copy the 'hddemo.out' textfile to your '/submit' directory which is generated when you execute this Linux command: $ ./hddemo > hddemo.out In addition to these binaries, you need to turn in (to your Instructor's mailbox in room HRN-208) paper printouts of your three textfiles showing your handwritten name on each page ('hd.c', 'hddemo.cpp', 'hddemo.out'). These printouts must be easily readable by your instructor (so avoid use of tiny fonts, depleted toner-cartridges, or long lines which exceed the page-width). Disregard of these guidelines WILL affect your grade. _______________________________________________________________________ (c) Allan B. Cruse University of San Francisco Spring 2005