Open connect function handler

Updated: May 06, 2022

Prototype:

int (*open) (resmgr_context_t *ctp,
             io_open_t *msg,
             RESMGR_HANDLE_T *handle,
             void *extra ) 

Classification:

Connect

Default handler:

iofunc_open_default()

Helper functions:

iofunc_ability_check(), iofunc_ocb_attach(), iofunc_open()

Client functions:

open(), openat(), fopen(), sopen() (and others)

Messages:

_IO_CONNECT with one of _IO_CONNECT_COMBINE, _IO_CONNECT_COMBINE_CLOSE or _IO_CONNECT_OPEN subtypes.

Data structure:

struct _io_connect {
  // internal fields (as described above)
  uint16_t path_len;
  uint8_t  extra_type;
  uint16_t extra_len;
  char     path [1];
};

struct _io_connect_link_reply {
  uint32_t reserved1;
  uint32_t file_type;
  uint8_t  eflag;
  uint8_t  reserved2[1];
  uint16_t chroot_len;
  uint32_t umask;
  uint16_t nentries;
  uint16_t path_len;
};

struct _io_connect_ftype_reply {
  uint16_t status;      /* Typically an errno */
  uint16_t reserved;
  uint32_t file_type;   /* _FTYPE_? in sys/ftype.h */
};

typedef union {
  struct _io_connect             connect;
  struct _io_connect_link_reply  link_reply;
  struct _io_connect_ftype_reply ftype_reply;
} io_open_t;

Description:

This is the handler function for new file descriptors. It checks that the client indeed has the appropriate permissions to open the file, binds the OCB to the internal library structures (via resmgr_bind_ocb(), or iofunc_ocb_attach()), and returns an errno. Note that not all input and output structure members are relevant for this function.

Returns:

The status via the helper macro _IO_SET_CONNECT_RET().

Referenced by:

resmgr_connect_funcs_t connect table

Permission checking:

When you override the default function, QNX recommends that you call iofunc_open_default() (which implements several permission checks depending on the access requested) before you implement any additional functionality. Note that because a file can be opened without read or write permissions, it is not sufficient to check that iofunc_open_default() (or the related iofunc_open()) returns EOK before you implement things like locking (e.g., for a resource that should only be opened by one client at a time).