Call the ioctl function of the device on the command line. In Linux, it seems that only the ioctl function is used to directly operate the device. Not many parameters are accepted, and they all correspond one to one.
Blockdev-call the block device control program from the command line
Blockdev [Options]Commands Devices
The blockdev tool allows you to call the block device control program from the command line.
-Setro: set the device to read-only.
-Whether the getro reading device is read-only (if the value is 1 or 0, the device can be read and written)
-Setrw: Set to read/write.
-Getss prints the device's sector size, usually 512
-Getsize: prints the set capacity, which is calculated by 512 bytes per sector.
-Setra N: Set the pre-read sector (512 bytes) to N. Set readahead to N 512-byte sectors.
-Getra print readahead (pre-read sector)
-Flushbufs refresh buffer
-Rereadpt: Re-reads the partition table.
I think-setro and setrw are useful. This mount-O RO (RW) is different. Mount is read-only or readable to a partition at the file system level. Blockdev is set to read-only and read-write at the level of settings.
The output result of the following command is clear at a glance.
[Root @ lancy ~] # Blockdev-setro/dev/hda4
[Root @ lancy ~] # Blockdev-getro/dev/hda4
1
[Root @ lancy ~] # Mount/dev/hda4/MISC-O RW
Mount: block device/dev/hda4 is write-protected, mounting read-only
[Root @ lancy ~] # Umount/dev/hda4
[Root @ lancy ~] # Blockdev-setrw/dev/hda4
[Root @ lancy ~] # Blockdev-getro/dev/hda4
0
[Root @ lancy ~] # Mount/dev/hda4/MISC-O RW
[Root @ lancy ~] # Touch/MISC/One
[Root @ lancy ~] # Umount/dev/hda4
[Root @ lancy ~] # Mount/dev/hda4/MISC-O Ro
[Root @ lancy ~] # Rm-F/MISC/One
RM: cannot delete '/MISC/one': Read-Only File System