Think ioctl()
Think ioctl()
Posted Jul 20, 2018 15:16 UTC (Fri) by abatters (✭ supporter ✭, #6932)In reply to: The problem with the asynchronous bsg interface by dullfire
Parent article: The problem with the asynchronous bsg interface
Here is an example:
Example: SCSI READ command using direct I/O
allocate buffer to hold data being read
start SCSI READ command via write() syscall to sg, passing address of buffer
wait for command completion; SCSI HBA DMAs directly to buffer
use read() syscall to sg to get command result
If using indirect I/O, you could design an interface where the buffer was passed to the read() syscall at command completion (although the sg driver doesn't work like that). But using direct I/O, the kernel needs the buffer when the command is started, so it is passed in the write() syscall. So there is no way to map "start a command" to the original meaning of the write() (or writev()) syscall using direct I/O. It makes more sense to think of it as an ioctl().