Handling stat()

Updated: May 06, 2022

Your resource manager will receive an _IO_STAT message when a client calls stat(), lstat(), or fstat(). You usually don't need to provide your own handler for this message. The prototype for the io_stat handler is as follows:

int io_stat ( resmgr_context_t *ctp,
              io_stat_t *msg,
              RESMGR_OCB_T *ocb)

The default handler for the _IO_STAT message, iofunc_stat_default(), calls iofunc_time_update() to ensure that the time entries in the ocb->attr structure are current and valid, and then calls the iofunc_stat_format() helper function to fill in the stat structure based on the information in the ocb->attr structure.

The io_stat_t structure holds the _IO_STAT message received by the resource manager:

struct _io_stat {
    uint16_t                    type;
    uint16_t                    combine_len;
    union {
       uint32_t                 zero;
       uint32_t                 format;

typedef union {
    struct _io_stat             i;
    struct __stat_t32_2001      o_t32_2001;
    struct __stat_t32_2008      o_t32_2008;
    struct __stat_t64_2008      o_t64_2008;
    struct stat                 o;
} io_stat_t;

As with all the I/O messages, this structure is a union of an input message (coming to the resource manager) and an output or reply message (going back to the client). The i member is a structure of type _io_stat that contains the following members:

If the message is a combine message, _IO_COMBINE_FLAG is set in this member. For more information, see the Combine Messages chapter of this guide.
(QNX Neutrino 7.0 or later) The form of the information; one of the following:
  • _STAT_FORM_UNSET — unknown; this is assumed to be the same as _STAT_FORM_T32_2001
  • _STAT_FORM_T32_2001 — 32-bit fields, POSIX 2001
  • _STAT_FORM_T32_2008 — 32-bit fields, POSIX 2008
  • _STAT_FORM_T64_2008 — 64-bit fields, POSIX 2008
  • _STAT_FORM_SYS_2008_STAT_FORM_T32_2008 in programs compiled for a 32-bit architecture, or _STAT_FORM_T64_2008 in programs compiled for a 64-bit architecture.
  • _STAT_FORM_PREFERRED — the preferred form: _STAT_FORM_T32_2001 in programs compiled for a 32-bit architecture, or _STAT_FORM_T64_2008 in programs compiled for a 64-bit architecture.

The o* members are variants of a struct stat, corresponding to the requested form; for more information, see the entry for struct stat in the QNX Neutrino C Library Reference.

If you write your own handler, it should return the status via the helper macro _RESMGR_STATUS() and the struct stat via message reply.

If your resource manager is for a filesystem, you might want to include the stat information in the reply for other messages. For more information, see Returning directory entries from _IO_READ in the Filesystem Resource Managers chapter of this guide.