For various block devices, the kernel uses a block device table blk_dev[] to manage. Each block device occupies an entry in the block device table.
The data structure of each block device entry in the block device table is:
// Block device processing structure.
struct blk_dev_struct {
void (*request_fn)(void); // Request handler function pointer.
struct request * current_request; // The currently processed request structure.
}
// Below is the structure of the item in the request queue. Among them, if the field dev = -1 , it means that the item in the queue is not used.
// The field cmd can take the constant READ ( 0 ) or WRITE ( 1 ) (defined in include/linux/fs.h ).
// Among them, the kernel does not use the waiting pointer, instead the kernel uses the waiting queue of the buffer block. because
// Waiting for a buffer block is equivalent to waiting for the request item to complete.
struct request {
intdev; /* -1 if no request */ // The device number of the request.
intcmd; /* READ or WRITE */ // READ或WRITE命令。
int errors; // Number of errors generated during operation.
unsigned long sector ; // Start sector. (1 block = 2 sectors )
unsigned long nr_sectors; // Number of read / write sectors.
char *buffer; // Data buffer.
struct task_struct * waiting; // where the task waits for the request to complete the operation (queue).
struct buffer_head * bh; // Buffer head pointer (include/linux/fs.h,68) .
struct request * next; // Point to the next request item.
};