Sample Header Ad - 728x90

Proper (working) way to return an int pointer through STREAMS?

0 votes
0 answers
30 views
I had been doing some work with an old SVR4 box with serial i/o when I found that the driver for the serial card did not support TIOCMGET through an ioctl call (e.g. ioctl(fd, TIOCMGET, &arg);). Having the source for the driver, and looking at it - it didn't seem too hard to add an answer to the call. However, I've run into a bit of a snag in that what I am doing doesn't seem to work. Looking at the driver, it has the following code to service TCGETS: case TCGETS: { /* immediate parm retrieve */ register struct termios *cb; if (mp->b_cont) /* Bad user supplied parameter */ freemsg(mp->b_cont); if (!(bp1 = allocb(sizeof(struct termios), BPRI_MED))) { putbq(q, mp); bufcall(sizeof(struct termios), BPRI_MED, getoblk, (long)tp); return; } mp->b_cont = bp1; cb = (struct termios *)mp->b_cont->b_rptr; cb->c_iflag = tp->t_iflag; cb->c_oflag = tp->t_oflag; cb->c_cflag = tp->t_cflag; mp->b_cont->b_wptr += sizeof(struct termios); mp->b_datap->db_type = M_IOCACK; iocbp->ioc_count = sizeof(struct termios); putnext(RD(q), mp); break; } My thought was simply to copy this code and rather than return a termios structure, just return the int. As such, my code is similar: case TIOCMGET: { /* immediate parm retrieve */ register int *cb; if (mp->b_cont) /* Bad user supplied parameter */ freemsg(mp->b_cont); if (!(bp1 = allocb(sizeof(int), BPRI_MED))) { putbq(q, mp); bufcall(sizeof(int), BPRI_MED, getoblk, (long)tp); return; } mp->b_cont = bp1; cb = (int *)mp->b_cont->b_rptr; /* my original attempt to get some bits */ *cb = (ql->carrier * TIOCM_CAR | ql->rts * TIOCM_RTS | (ql->lp->command & 1) * TIOCM_DTR) /* Tried this to debug: *cb = 0; Doesn't seem to change the variable I pass in */ /* Tried this, compiles fine, *(int *)mp->b_cont->b_rptr = 0; but I get an improper argument passed error while running */ /* qreply(q, mp); not in my code, was a note to try it */ mp->b_cont->b_wptr += sizeof(int); mp->b_datap->db_type = M_IOCACK; iocbp->ioc_count = sizeof(int); putnext(RD(q), mp); break; } Making the call as shown previously, ioctl(fd, TIOCMGET, &arg), the arg value does not seem to get changed. I've tried a couple different attempts to return a value of 0 in case the problem was in my bit assignment code. However, I've not had any luck. I did write a program to make sure that TCGETS works as it should - and it does. So I'm not sure where I'm going wrong - probably something incredibly stupid and right in front of me. Hopefully that it is SVR4 and STREAMS isn't so arcane to put an answer out of reach. Thanks to all who look and try to help. Mack
Asked by mackbw (1 rep)
Aug 30, 2019, 08:48 PM
Last activity: Sep 9, 2019, 08:39 PM