The iofunc_ocb_t (Open Control Block) structure

The Open Control Block (OCB) maintains the state information about a particular session involving a client and a resource manager. It's created during open() handling and exists until a close() is performed.

This structure is used by the iofunc layer helper functions. (In the Extending the POSIX-Layer Data Structures chapter, we'll show you how to extend this to include your own data).

The OCB structure contains at least the following:

typedef struct _iofunc_ocb {
    IOFUNC_ATTR_T   *attr;
    int32_t         ioflag;
    off_t           offset;
    uint16_t        sflag;
    uint16_t        flags;
} iofunc_ocb_t;

where the values represent:

attr
A pointer to the attribute structure (see below).
ioflag
Contains the mode (e.g., reading, writing, blocking) that the resource was opened with. This information is inherited from the io_connect_t structure that's available in the message passed to the io_open handler. The open modes (as passed to open() on the client side) are converted to the ioflag values as follows:
Open mode ioflag value
O_RDONLY _IO_FLAG_RD
O_RDWR _IO_FLAG_RD | _IO_FLAG_WR
O_WRONLY _IO_FLAG_WR
offset
The read/write offset into the resource (e.g., our current lseek() position within a file). Your resource manager can modify this member.
sflag
Defines the sharing mode. This information is inherited from the io_connect_t structure that's available in the message passed to the io_open handler.
flags
A combination of zero or more of the following bits:
  • IOFUNC_OCB_PRIVILEGED — a privileged process (i.e., root) performed the open()
  • IOFUNC_OCB_MMAP — this OCB is in use by a mmap() call on the client side
  • IOFUNC_OCB_MMAP_UNIQUE — a hint for the mmap() handler to provide a unique mapping

Additionally, you can use flags in the range defined by IOFUNC_OCB_FLAGS_PRIVATE (see <sys/iofunc.h>) for your own purposes. Your resource manager can modify these flags.