Retrieve and send data through IO manager

Hi,
Can anybody give me a direction on how to retrieve and send data to a named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I send and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1) {
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie

open( “/dev/memdev”);
lseek ( address you want to access)
read ( …)
write (…)
close()

Internaly open/lseek/read/write/… end up sending a message
to the device manager you connected to via open. Hence
the code you looked at is the receving end of the messages.

Does that answer your question?

“Jackie” <jackie@neontech.com> wrote in message
news:98t71c$i30$1@inn.qnx.com

Hi,
Can anybody give me a direction on how to retrieve and send data to a
named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I send
and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1) {
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie

Basically, I want to retrieve the data that the device write out through the
IO manager IO_WRITE, and pack those data into pppoe packet, and send it out
through ethernet. And, send the ppp data that I have packeted to the device
through IO manager IO_READ.
But I am not sure how to retrieve and send those data.
In IO_READ, how can I pass my ppp data to /dev/pppoe device?
How can I let the device read the data from my buffer?
In IO_WRITE, I am thinking to make the following modification.

p = MK_FP(sel, 0);
_setmx(&mx_entry[0], p, size);

memcpy(mybuffer, p, msg.write_reply.nbytes);

Thanks for any input,
Jackie

“Mario Charest” <mcharest@void_zinformatic.com> wrote in message
news:98tvs4$9k3$1@nntp.qnx.com

open( “/dev/memdev”);
lseek ( address you want to access)
read ( …)
write (…)
close()

Internaly open/lseek/read/write/… end up sending a message
to the device manager you connected to via open. Hence
the code you looked at is the receving end of the messages.

Does that answer your question?

“Jackie” <> jackie@neontech.com> > wrote in message
news:98t71c$i30$> 1@inn.qnx.com> …
Hi,
Can anybody give me a direction on how to retrieve and send data to a
named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I send
and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1) {
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie
\

Jackie <jackie@neontech.com> wrote:

Basically, I want to retrieve the data that the device write out through the
IO manager IO_WRITE, and pack those data into pppoe packet, and send it out
through ethernet. And, send the ppp data that I have packeted to the device
through IO manager IO_READ.
But I am not sure how to retrieve and send those data.

You are an IO manager. The application (pppd) will open/read/write/close
you as Mario showes the sample.

The sample code you have present you how to “retrive data in a write”,
and “return data in a read”.

Basically the client (pppd) do a write(), IO manager will got a _IO_WRITE,
and the Readmsgmx() will get all the datas client is writing.
In case of a read(), you will got a _IO_READ, and you prepare the
data, then Replymx() to it.

-xtang

IO_READ, how can I pass my ppp data to /dev/pppoe device?
How can I let the device read the data from my buffer?
In IO_WRITE, I am thinking to make the following modification.

p = MK_FP(sel, 0);
_setmx(&mx_entry[0], p, size);

memcpy(mybuffer, p, msg.write_reply.nbytes);

Thanks for any input,
Jackie

“Mario Charest” <mcharest@void_zinformatic.com> wrote in message
news:98tvs4$9k3$> 1@nntp.qnx.com> …

open( “/dev/memdev”);
lseek ( address you want to access)
read ( …)
write (…)
close()

Internaly open/lseek/read/write/… end up sending a message
to the device manager you connected to via open. Hence
the code you looked at is the receving end of the messages.

Does that answer your question?

“Jackie” <> jackie@neontech.com> > wrote in message
news:98t71c$i30$> 1@inn.qnx.com> …
Hi,
Can anybody give me a direction on how to retrieve and send data to a
named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I send
and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1) {
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie
\

I can retrieve data from IO_WRITE by memcpy(mybuf, msg.write.data,
msg.write_reply.nbytes).
But, I am not sure why I never get the IO_READ request from pppd.
Do I need to implement IO_SELECT? What should I return to pppd? Is there
any special IO request that I should handle?
In the freebsd pppd source code, it will call select to check if any fd has
data ready to be read. Is the qnx pppd also implemented in this way?

Thanks,
Jackie
“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:991d4h$7ql$2@nntp.qnx.com

Jackie <> jackie@neontech.com> > wrote:
Basically, I want to retrieve the data that the device write out through
the
IO manager IO_WRITE, and pack those data into pppoe packet, and send it
out
through ethernet. And, send the ppp data that I have packeted to the
device
through IO manager IO_READ.
But I am not sure how to retrieve and send those data.

You are an IO manager. The application (pppd) will open/read/write/close
you as Mario showes the sample.

The sample code you have present you how to “retrive data in a write”,
and “return data in a read”.

Basically the client (pppd) do a write(), IO manager will got a _IO_WRITE,
and the Readmsgmx() will get all the datas client is writing.
In case of a read(), you will got a _IO_READ, and you prepare the
data, then Replymx() to it.

-xtang

IO_READ, how can I pass my ppp data to /dev/pppoe device?
How can I let the device read the data from my buffer?
In IO_WRITE, I am thinking to make the following modification.

p = MK_FP(sel, 0);
_setmx(&mx_entry[0], p, size);

memcpy(mybuffer, p, msg.write_reply.nbytes);

Thanks for any input,
Jackie

“Mario Charest” <mcharest@void_zinformatic.com> wrote in message
news:98tvs4$9k3$> 1@nntp.qnx.com> …

open( “/dev/memdev”);
lseek ( address you want to access)
read ( …)
write (…)
close()

Internaly open/lseek/read/write/… end up sending a message
to the device manager you connected to via open. Hence
the code you looked at is the receving end of the messages.

Does that answer your question?

“Jackie” <> jackie@neontech.com> > wrote in message
news:98t71c$i30$> 1@inn.qnx.com> …
Hi,
Can anybody give me a direction on how to retrieve and send data to a
named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to
handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I
send
and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1) {
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie


\

The pppd will send IO_FLAGS but I didn’t receive any IO_SELECT yet.
How should I handle IO_FLAGS?
“Jackie” <jackie@neontech.com> wrote in message
news:9950rn$gdi$1@inn.qnx.com

I can retrieve data from IO_WRITE by memcpy(mybuf, msg.write.data,
msg.write_reply.nbytes).
But, I am not sure why I never get the IO_READ request from pppd.
Do I need to implement IO_SELECT? What should I return to pppd? Is there
any special IO request that I should handle?
In the freebsd pppd source code, it will call select to check if any fd
has
data ready to be read. Is the qnx pppd also implemented in this way?

Thanks,
Jackie
“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:991d4h$7ql$> 2@nntp.qnx.com> …
Jackie <> jackie@neontech.com> > wrote:
Basically, I want to retrieve the data that the device write out
through
the
IO manager IO_WRITE, and pack those data into pppoe packet, and send
it
out
through ethernet. And, send the ppp data that I have packeted to the
device
through IO manager IO_READ.
But I am not sure how to retrieve and send those data.

You are an IO manager. The application (pppd) will open/read/write/close
you as Mario showes the sample.

The sample code you have present you how to “retrive data in a write”,
and “return data in a read”.

Basically the client (pppd) do a write(), IO manager will got a
_IO_WRITE,
and the Readmsgmx() will get all the datas client is writing.
In case of a read(), you will got a _IO_READ, and you prepare the
data, then Replymx() to it.

-xtang

IO_READ, how can I pass my ppp data to /dev/pppoe device?
How can I let the device read the data from my buffer?
In IO_WRITE, I am thinking to make the following modification.

p = MK_FP(sel, 0);
_setmx(&mx_entry[0], p, size);

memcpy(mybuffer, p, msg.write_reply.nbytes);

Thanks for any input,
Jackie

“Mario Charest” <mcharest@void_zinformatic.com> wrote in message
news:98tvs4$9k3$> 1@nntp.qnx.com> …

open( “/dev/memdev”);
lseek ( address you want to access)
read ( …)
write (…)
close()

Internaly open/lseek/read/write/… end up sending a message
to the device manager you connected to via open. Hence
the code you looked at is the receving end of the messages.

Does that answer your question?

“Jackie” <> jackie@neontech.com> > wrote in message
news:98t71c$i30$> 1@inn.qnx.com> …
Hi,
Can anybody give me a direction on how to retrieve and send data to
a
named
device(async) through the device’s IO manager?
In Qnx’s sample code Memdev.c, there are the following codes to
handle
IO_READ and IO_WRITE. Can anybody explain how it works? How can I
send
and
retrieve the data through that interface?
struct ocb {
mode_t mode;
int count;
off_t offset;
};

case _IO_READ:
ocb = (struct ocb *)__get_fd(pid, msg.read.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IREAD) == 0) {
msg.status = EBADF;
break;
}
if((sel = qnx_segment_overlay(ocb->offset, msg.read.nbytes)) == -1)
{
msg.status = errno;
break;
}
size = msg.read.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
_setmx(&mx_entry[1], MK_FP(sel, 0), size);
msg.read_reply.status = EOK;
msg.read_reply.nbytes = size;
msg.read_reply.zero = 0;
_setmx(&mx_entry[0], &msg,
sizeof(struct _io_read_reply) - sizeof(msg.read_reply.data));
Replymx(pid, 2, &mx_entry);
nbytes = 0;
qnx_segment_free(sel);
ocb->offset += size;
fstat_reply.stat.st_atime = *timep;
break;

case _IO_WRITE:
ocb = (struct ocb *)__get_fd(pid, msg.write.fd, fd_ctrl);
if(ocb == (struct ocb *)0 || ocb == (struct ocb *)-1) {
msg.status = EBADF;
break;
}
if((ocb->mode & S_IWRITE) == 0) {
msg.status = EBADF;
break;
}
size = msg.write.nbytes;
if(ocb->offset + size > endmem)
size = endmem - ocb->offset;
if((sel = qnx_segment_overlay(ocb->offset, size)) == -1) {
msg.status = errno;
break;
}
_setmx(&mx_entry[0], MK_FP(sel, 0), size);
msg.write_reply.nbytes = Readmsgmx(pid,
sizeof(struct _io_write) - sizeof(msg.write.data),
1, &mx_entry);
if(msg.write_reply.nbytes == -1) {
msg.write_reply.status = errno;
nbytes = sizeof(msg.write_reply.status);
} else {
msg.write_reply.status = EOK;
nbytes = sizeof(msg.write_reply);
ocb->offset += msg.write_reply.nbytes;
}
qnx_segment_free(sel);
fstat_reply.stat.st_mtime =
fstat_reply.stat.st_atime = *timep;
break;
}

Thanks,
Jackie




\