Next: , Previous: Device Reply Server, Up: Device Interface

10.2 Device Open

— Function: kern_return_t device_open (mach_port_t master_port, dev_mode_t mode, dev_name_t name, device_t *device)

The function device_open opens the device name and returns a port to it in device. The open count for the device is incremented by one. If the open count was 0, the open handler for the device is invoked.

master_port must hold the master device port. name specifies the device to open, and is a string up to 128 characters long. mode is the open mode. It is a bitwise-or of the following constants:

Request read access for the device.
Request write access for the device.
Do not delay an open.

The function returns D_SUCCESS if the device was successfully opened, D_INVALID_OPERATION if master_port is not the master device port, D_WOULD_BLOCK is the device is busy and D_NOWAIT was specified in mode, D_ALREADY_OPEN if the device is already open in an incompatible mode and D_NO_SUCH_DEVICE if name does not denote a know device.

— Function: kern_return_t device_open_request (mach_port_t master_port, mach_port_t reply_port, dev_mode_t mode, dev_name_t name)
— Function: kern_return_t ds_device_open_reply (mach_port_t reply_port, kern_return_t return, device_t *device)

This is the asynchronous form of the device_open function. device_open_request performs the open request. The meaning for the parameters is as in device_open. Additionally, the caller has to supply a reply port to which the ds_device_open_reply message is sent by the kernel when the open has been performed. The return value of the open 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.