The message structures passed to the io_read, io_write, and io_openfd handlers contain a member called xtype. From struct _io_read:
struct _io_read { ... uint32_t xtype; ... }
Basically, the xtype contains extended information that can be used to adjust the behavior of a standard I/O function. This information includes a type and optionally some flags:
To isolate the type from the flags in _IO_READ and _IO_WRITE messages, use a bitwise AND of the xtype member with _IO_XTYPE_MASK:
if ((msg->i.xtype & _IO_XTYPE_MASK) == ...)
Most resource managers care about only a few types:
For example:
struct myread_offset { struct _io_read read; struct _xtype_offset offset; }
Some resource managers can be sure that their clients will never call pread*() or pwrite*(). (For example, a resource manager that's controlling a robot arm probably wouldn't care.) In this case, you can treat this type of message as an error.
struct myreadcond { struct _io_read read; struct _xtype_readcond cond; }
As with _IO_XTYPE_OFFSET, if your resource manager isn't prepared to handle readcond(), you can treat this type of message as an error.
The following types are used for special purposes, so your resource manager probably doesn't need to handle them:
The xtype member may also include some flags. Your resource manager might be interested in the following:
The readdir() function sets this flag in an _IO_READ message if you've used dircntl() to set D_FLAG_STAT for the directory.
dircntl() command | xtype flag | Structure |
---|---|---|
D_FLAG_STAT_FORM_UNSET | _IO_XFLAG_DIR_STAT_FORM_UNSET | The default for the 32- or 64-bit architecture that you're using |
D_FLAG_STAT_FORM_T32_2001 | _IO_XFLAG_DIR_STAT_FORM_T32_2001 | struct __stat_t32_2001 |
D_FLAG_STAT_FORM_T32_2008 | _IO_XFLAG_DIR_STAT_FORM_T32_2008 | struct __stat_t32_2008 |
D_FLAG_STAT_FORM_T64_2008 | _IO_XFLAG_DIR_STAT_FORM_T64_2008 | struct __stat_t64_2008 |
You can use _IO_XFLAG_DIR_STAT_FORM_MASK to isolate these bits from the rest of the xtype.
The other defined flags are used for special purposes, so your resource manager probably doesn't need to handle them: