Next: , Previous: Device Read, Up: Device Interface


10.5 Device Write

— Function: kern_return_t device_write (device_t device, dev_mode_t mode, recnum_t recnum, io_buf_ptr_t data, mach_msg_type_number_t data_count, int *bytes_written)

The function device_write writes data_count bytes from the buffer data to device. The number of bytes actually written is returned in bytes_written.

If mode is D_NOWAIT, the function returns without waiting for I/O completion. Otherwise mode should be 0. recnum is the record number to be written, its meaning is device specific.

The function returns D_SUCCESS if some data was successfully written and D_NO_SUCH_DEVICE if device does not denote a device port or the device is dead or not completely open.

— Function: kern_return_t device_write_inband (device_t device, dev_mode_t mode, recnum_t recnum, int bytes_wanted, io_buf_ptr_inband_t *data, mach_msg_type_number_t *data_count)

The device_write_inband function works as the device_write function, except that the data is sent “in-line” in the request IPC message (see Memory).

— Function: kern_return_t device_write_request (device_t device, mach_port_t reply_port, dev_mode_t mode, recnum_t recnum, io_buf_ptr_t data, mach_msg_type_number_t data_count)
— Function: kern_return_t ds_device_write_reply (mach_port_t reply_port, kern_return_t return_code, int bytes_written)

This is the asynchronous form of the device_write function. device_write_request performs the write request. The meaning for the parameters is as in device_write. Additionally, the caller has to supply a reply port to which the ds_device_write_reply message is sent by the kernel when the write has been performed. The return value of the write operation is stored in return_code.

As neither function receives a reply message, only message transmission errors apply. If no error occurs, KERN_SUCCESS is returned.

— Function: kern_return_t device_write_request_inband (device_t device, mach_port_t reply_port, dev_mode_t mode, recnum_t recnum, io_buf_ptr_t data, mach_msg_type_number_t data_count)
— Function: kern_return_t ds_device_write_reply_inband (mach_port_t reply_port, kern_return_t return_code, int bytes_written)

The device_write_request_inband and ds_device_write_reply_inband functions work as the device_write_request and ds_device_write_reply functions, except that the data is sent “in-line” in the request IPC message (see Memory).