Handling lseek()

Your resource manager will receive an _IO_LSEEK message when a client calls lseek(), fseek(), or rewinddir().

Note: A resource manager that handles directories will also need to interpret the _IO_LSEEK message for directory operations.

The prototype for the io_lseek handler is as follows:

int io_lseek ( resmgr_context_t *ctp,
               io_lseek_t *msg,
               RESMGR_OCB_T *ocb)

The default handler, iofunc_lseek_default(), simply calls the iofunc_lseek() helper function.

The io_lseek_t structure is (once again), a union of an input message and an output message:

struct _io_lseek {
  uint16_t         type;
  uint16_t         combine_len;
  short            whence;
  uint16_t         zero;
  uint64_t         offset;

typedef union {
  struct _io_lseek i;
  uint64_t         o;
} io_lseek_t;

The whence and offset members are passed from the client's lseek() function. The routine should adjust the OCB's offset parameter after interpreting the whence and offset parameters from the message and should return the new offset or an error.

The handler should return the status via the helper macro _RESMGR_STATUS(), and optionally (if no error occurred, and if the message isn't part of a combine message) the current offset.