The Header File blk.h
All block drivers should include the header file
<linux/blk.h>. This file defines much of the
common code that is used in block drivers, and it provides functions
for dealing with the I/O request queue.
Actually, the blk.h header is quite unusual,
because it defines several symbols based on the symbol
MAJOR_NR, which must be declared by the driver
before it includes the header. This convention
was developed in the early days of Linux, when all block devices had
preassigned major numbers and modular block drivers were not
supported.
If you look at blk.h, you’ll see that several
device-dependent symbols are declared according to the value of
MAJOR_NR, which is expected to be known in advance.
However, if the major number is dynamically assigned, the driver has
no way to know its assigned number at compile time and cannot
correctly define MAJOR_NR. If
MAJOR_NR is undefined, blk.h
can’t set up some of the macros used with the request queue.
Fortunately, MAJOR_NR can be defined as an integer
variable and all will work fine for add-on block drivers.
blk.h makes use of some other predefined,
driver-specific symbols as well. The following list describes the
symbols in <linux/blk.h> that must be defined
in advance; at the end of the list, the code used in
sbull is shown.
-
MAJOR_NR This symbol is used to access a few arrays, in particular
blk_devandblksize_size. A custom driver like sbull, which is unable to assign a constant value to the symbol, should ...