handling open() mode flags in resource manager

What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?

Here’s my problem:

If I open my device with open() call:

fildes=open(device,O_RDONLY);

My resource manager io_open belowe prints “O_WRONLY”

int my_io_open (resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T *mbox,
void *extra)
{
int mask=0,val=0,reg=0;
int open_mode=0;

open_mode=msg->connect.ioflag&0x3;
if(open_mode==O_WRONLY)printf(“O_WRONLY\n”);





When I’m handling call:
fildes=open(device,O_RDONLY);
I get ioflag=0x1

more examples:
fildes=open(device,O_WRONLY);
I get ioflag=0x2

fildes=open(device,O_RDWR);
I get ioflag=0x3

and fcntl.h says:
#define O_RDONLY 000000 /* Read-only mode /
#define O_WRONLY 000001 /
Write-only mode /
#define O_RDWR 000002 /
Read-Write mode */

Of course I could assume that mode in ioflag is mode in fcntl + 1…

Thanks
Martin

new to QNX and c but reading your code you are anding with &0x3 woudl it
not be && instead of one &, Now I’m only learning so hopefully this isn’t
the completely wrong ie does one & mean hex and two not mean and I would
look at this, what is the value of msg->connect.ioflag

I think you are adding them together therefore your condition matches
add this line and test it
if(open_mode==O_RDWR)printf(“O_RDWR\n”);

“Martin Nylund” <mnylund@emtrion.de> wrote in message
news:cl8ek8$rfv$1@inn.qnx.com

What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?

Here’s my problem:

If I open my device with open() call:

fildes=open(device,O_RDONLY);

My resource manager io_open belowe prints “O_WRONLY”

int my_io_open (resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T
*mbox,
void *extra)
{
int mask=0,val=0,reg=0;
int open_mode=0;

open_mode=msg->connect.ioflag&0x3;
if(open_mode==O_WRONLY)printf(“O_WRONLY\n”);
.
.
.


When I’m handling call:
fildes=open(device,O_RDONLY);
I get ioflag=0x1

more examples:
fildes=open(device,O_WRONLY);
I get ioflag=0x2

fildes=open(device,O_RDWR);
I get ioflag=0x3

and fcntl.h says:
#define O_RDONLY 000000 /* Read-only mode /
#define O_WRONLY 000001 /
Write-only mode /
#define O_RDWR 000002 /
Read-Write mode */

Of course I could assume that mode in ioflag is mode in fcntl + 1…

Thanks
Martin
\

No. the single & means a logic AND instead of a logic comparison when using
two (&&).

Per example :
int a = 0xff;
int b;

b = a & 0x3; // b will equals 0x3;

b = a && 0x3; // Will first evaluate a (as being true) and evaluate 0x3
(being true also)… result true (then 1)


“aldur” <askey@tarmail.com> wrote in message
news:cl8sqo$8gq$1@inn.qnx.com

new to QNX and c but reading your code you are anding with &0x3 woudl it
not be && instead of one &, Now I’m only learning so hopefully this isn’t
the completely wrong ie does one & mean hex and two not mean and I would
look at this, what is the value of msg->connect.ioflag

I think you are adding them together therefore your condition matches
add this line and test it
if(open_mode==O_RDWR)printf(“O_RDWR\n”);

“Martin Nylund” <> mnylund@emtrion.de> > wrote in message
news:cl8ek8$rfv$> 1@inn.qnx.com> …
What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?

Here’s my problem:

If I open my device with open() call:

fildes=open(device,O_RDONLY);

My resource manager io_open belowe prints “O_WRONLY”

int my_io_open (resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T
*mbox,
void *extra)
{
int mask=0,val=0,reg=0;
int open_mode=0;

open_mode=msg->connect.ioflag&0x3;
if(open_mode==O_WRONLY)printf(“O_WRONLY\n”);
.
.
.


When I’m handling call:
fildes=open(device,O_RDONLY);
I get ioflag=0x1

more examples:
fildes=open(device,O_WRONLY);
I get ioflag=0x2

fildes=open(device,O_RDWR);
I get ioflag=0x3

and fcntl.h says:
#define O_RDONLY 000000 /* Read-only mode /
#define O_WRONLY 000001 /
Write-only mode /
#define O_RDWR 000002 /
Read-Write mode */

Of course I could assume that mode in ioflag is mode in fcntl + 1…

Thanks
Martin


\

Martin Nylund wrote:

What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?
Of course I could assume that mode in ioflag is mode in fcntl + 1…

This is indeed what happens. msg->connect.ioflag value has + 1 so
to convert the modes to a bitmask (see <sys/iomsg.h> and the
_IO_FLAG_RD and _IO_FLAG_WR manifests), which allows for write
access to be checked with “if (msg->connect.ioflag & _IO_FLAG_WR)”
rather than (O_WRONLY || O_RDWR). So, do not use the <fcntl.h>
values from within an IO manager, use the IO_FLAG* bit masks.

Thanks,

following implementation works fine:

int my_io_open (resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T *mbox,
void *extra)
{
int mask=0,val=0;
int open_mode=0;

open_mode=msg->connect.ioflag&_IO_FLAG_MASK;

printf("opening for ");
if(open_mode&(_IO_FLAG_RD|_IO_FLAG_RD))printf(“reading and writing…”);
else if(open_mode&_IO_FLAG_RD)printf(“reading…”);
else if(open_mode&_IO_FLAG_WR)printf(“writing…”);


The documentation for _io_connect could be a bit more clear about this. It
simply states:

ioflag
One of:
a… O_RDONLY – open for reading only.
b… O_RDWR – open for reading and writing. Opening a FIFO for read-write
is unsupported.
c… O_WRONLY – open for writing only.

“John Garvey” <jgarvey@qnx.com> schrieb im Newsbeitrag
news:cl8uoq$a97$1@inn.qnx.com

Martin Nylund wrote:
What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?
Of course I could assume that mode in ioflag is mode in fcntl + 1…

This is indeed what happens. msg->connect.ioflag value has + 1 so
to convert the modes to a bitmask (see <sys/iomsg.h> and the
_IO_FLAG_RD and _IO_FLAG_WR manifests), which allows for write
access to be checked with “if (msg->connect.ioflag & _IO_FLAG_WR)”
rather than (O_WRONLY || O_RDWR). So, do not use the <fcntl.h
values from within an IO manager, use the IO_FLAG* bit masks.

ahem the 10th line should of course be:
else if(open_mode==(_IO_FLAG_WR|_IO_FLAG_RD))…

“Martin Nylund” <mnylund@emtrion.de> schrieb im Newsbeitrag
news:claj9g$i1f$1@inn.qnx.com

Thanks,

following implementation works fine:

int my_io_open (resmgr_context_t *ctp, io_open_t *msg, IOFUNC_ATTR_T
*mbox, void *extra)
{
int mask=0,val=0;
int open_mode=0;

open_mode=msg->connect.ioflag&_IO_FLAG_MASK;

printf("opening for ");
if(open_mode&(_IO_FLAG_RD|_IO_FLAG_RD))printf(“reading and
writing…”);
else if(open_mode&_IO_FLAG_RD)printf(“reading…”);
else if(open_mode&_IO_FLAG_WR)printf(“writing…”);
.
.
.

The documentation for _io_connect could be a bit more clear about this. It
simply states:

ioflag
One of:
a… O_RDONLY – open for reading only.
b… O_RDWR – open for reading and writing. Opening a FIFO for read-write
is unsupported.
c… O_WRONLY – open for writing only.

“John Garvey” <> jgarvey@qnx.com> > schrieb im Newsbeitrag
news:cl8uoq$a97$> 1@inn.qnx.com> …
Martin Nylund wrote:
What’s the correct way to map/handle/interpret the
O_* (O_RDONLY, O_RDWR …) in the _io_connect of the
io_open call at resource manager side?
Of course I could assume that mode in ioflag is mode in fcntl + 1…

This is indeed what happens. msg->connect.ioflag value has + 1 so
to convert the modes to a bitmask (see <sys/iomsg.h> and the
_IO_FLAG_RD and _IO_FLAG_WR manifests), which allows for write
access to be checked with “if (msg->connect.ioflag & _IO_FLAG_WR)”
rather than (O_WRONLY || O_RDWR). So, do not use the <fcntl.h
values from within an IO manager, use the IO_FLAG* bit masks.