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