Hi
I am fairly new to QNX and have a question regarding resource managers.
I am writing a resource manager for a hardware device. In our setup, it does
not make sense, that the file representing the hardware can be opened more
than once as the clients would be contesting over the same device. I realise
that the clients could use O_EXCL in their open call to avoid this but to be
on the safe side I want to enforce this in the resource manager.
What I have done is:
struct DevAttr;
#define IOFUNC_ATTR_T struct DevAttr
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
typedef struct DevAttr
{
iofunc_attr_t attr;
int count;
} DevAttr;
int IoOpen(resmgr_context_t *ctp, io_open_t *msg, DevAttr *attr, void
*extra )
{
int result = EINVAL;
if (attr != NULL)
{
if (attr->attr.count == 0)
{
printf(“Opened connection number %d\n”,attr->attr.count);
attr->attr.count++;
result = iofunc_open_default(ctp, msg, &attr->attr, extra);
}
else
{
printf(“Cannot open device - already opened %d
times\n”,attr->attr.count);
result = EBUSY;
}
}
return result;
}
int IoCloseOcb (resmgr_context_t *ctp, void *reserved, RESMGR_OCB_T *ocb)
{
if (ocb->ocb.attr->attr.count > 0)
{
ocb->ocb.attr->attr.count–;
printf(“Decreased counter to %d\n”, ocb->ocb.attr->attr.count);
}
else
{
printf(“Count is %d\n”, ocb->ocb.attr->attr.count);
}
return (iofunc_close_ocb_default (ctp, reserved, &ocb->ocb));
}
This works like a charm, as soon as I have opened the file once, any try to
open it again fails with the error ‘file busy’.
However, unfortunately, it also means, that whenever I do an ls on the
directory which contains the file I get an error, indicating that my device
is busy as well.
What I would like is to disallow file open calls to the file for
reading/writing but to allow opening it for stat() etc, so it will show
properly in the directory. Is there any way to do this?
Thanks for any help
/urs