Полезная информация

next up previous contents
Next: Recognizing PC standard partitions Up: Initialization Previous: Initialization

The file blk.h

At the top of your driver code, after all other included header files, you need to write two lines of code:

tscreen614

where DEVICE_MAJOR is the major number of your device. drivers/block/blk.h requires the use of the MAJOR_NR define to set up many other defines and macros for your driver.

Now you need to edit blk.h. Under #ifdef MAJOR_NR, there is a section of defines that are conditionally included for certain major numbers, protected by #elif (MAJOR_NR == DEVICE_MAJOR). At the end of this list, you will add another section for your driver. In that section, the following lines are required:

tscreen621

DEVICE_NAME is simply the device name. See the other entries in blk.h for examples.

DEVICE_REQUEST is your strategy routine, which will do all the I/O on the device. See section gif for more details on the strategy routine.

DEVICE_ON and DEVICE_OFF are for devices that need to be turned on and off, like floppies. In fact, the floppy driver is currently the only device driver which uses these defines.

DEVICE_NR(device) is used to determine the number of the physical device from the minor device number. For instance, in the hd driver, since the second hard drive starts at minor 64, DEVICE_NR(device) is defined to be (MINOR(device)>>6).

If your driver is interrupt-driven, you will also set

tscreen636

which will become a variable automatically defined and used by the remainder of blk.h, specifically by the SET_INTR() and CLEAR_INTR macros.

You might also consider setting these defines:

tscreen641

where n is the number of jiffies (clock ticks; hundredths of a second on /386) to time out after if no interrupt is received. These are used if your device can become ``stuck'': a condition where the driver waits indefinitely for an interrupt that will never arrive. If you define these, they will automatically be used in SET_INTR to make your driver time out. Of course, your driver will have to be able to handle the possibility of being timed out by a timer. See section ?? for an explanation of how to do this.


next up previous contents
Next: Recognizing PC standard partitions Up: Initialization Previous: Initialization

Converted on:
Mon Apr 1 10:20:16 EST 1996