The ioctl Method
Like char devices, block devices can be acted on by using the ioctl system call. The only relevant difference between block and char ioctl implementations is that block drivers share a number of common ioctl commands that most drivers are expected to support.
The commands that block drivers usually handle are the following, declared in <linux/fs.h>.
-
BLKGETSIZE Retrieve the size of the current device, expressed as the number of sectors. The value of
argpassed in by the system call is a pointer to alongvalue and should be used to copy the size to a user-space variable. This ioctl command is used, for instance, by mkfs to know the size of the filesystem being created.-
BLKFLSBUF Literally, “flush buffers.” The implementation of this command is the same for every device and is shown later with the sample code for the whole ioctl method.
-
BLKRRPART Reread the partition table. This command is meaningful only for partitionable devices, introduced later in this chapter.
-
BLKRAGET,BLKRASET Used to get and change the current block-level read-ahead value (the one stored in the
read_aheadarray) for the device. ForGET, the current value should be written to user space as alongitem using the pointer passed to ioctl inarg; forSET, the new value is passed as an argument.-
BLKFRAGET,BLKFRASET Get and set the filesystem-level read-ahead value (the one stored in
max_readahead) for this device.-
BLKROSET,BLKROGET These commands are used to change ...