The 'buffer' should point to an object of type sg_io_hdr_t and 'count'
should be sizeof(sg_io_hdr_t) [it can be larger but the excess is ignored].
If the write() call succeeds then the 'count' is returned as the result.
Up to SG_MAX_QUEUE (16) write()s can be queued up before any finished
requests are completed by read(). An attempt to queue more than that will
result in an EDOM error.
[1]
The write() command should return more or
less immediately.
[2]
The version 2 sg driver defaulted the maximum queue length to 1 (and
made available the SG_SET_COMMAND_Q ioctl() to switch it to SG_MAX_QUEUE).
So for backward compatibility a file descriptor that only receives
sg_header structures in its write() will have a default "max" queue length
of 1. As soon as a sg_io_hdr_t structure is seen by a write() then the
maximum queue length is switched to SG_MAX_QUEUE on that file descriptor.
The "const" on the 'buffer' pointer is respected by the sg driver. Data
is read in from the sg_io_hdr object that is pointed to. Significantly
this is when the 'sbp' and the 'dxferp' are recorded internally (i.e.
not from the sg_io_hdr object given to the corresponding read() ).