Author: avg
Date: Fri Nov 11 15:00:13 2016
New Revision: 308528
URL: https://svnweb.freebsd.org/changeset/base/308528

Log:
  smbmsg: use a more convenient way of accessing data read from a slave
  
  Developers writing code for accessing /dev/smb may use this base utility
  as an example.  Now that SMB_READB, SMB_READW, SMB_PCALL behave as
  documented, wwe can use them in a more convenient way than before.
  
  MFC after:    4 weeks
  X-MFC after:  r308527

Modified:
  head/usr.sbin/smbmsg/smbmsg.c

Modified: head/usr.sbin/smbmsg/smbmsg.c
==============================================================================
--- head/usr.sbin/smbmsg/smbmsg.c       Fri Nov 11 14:41:02 2016        
(r308527)
+++ head/usr.sbin/smbmsg/smbmsg.c       Fri Nov 11 15:00:13 2016        
(r308528)
@@ -61,7 +61,7 @@ static int wflag;             /* word IO */
 
 static unsigned char ibuf[SMB_MAXBLOCKSIZE];
 static unsigned char obuf[SMB_MAXBLOCKSIZE];
-static unsigned short oword, iword;
+static unsigned short oword;
 
 /*
  * The I2C specs say that all addresses below 16 and above or equal
@@ -135,6 +135,8 @@ do_io(void)
 
        c.slave = slave;
        c.cmd = cflag;
+       c.rcount = 0;
+       c.wcount = 0;
 
        if (fmt == NULL && iflag > 0)
                fmt = wflag? wordfmt: bytefmt;
@@ -163,11 +165,9 @@ do_io(void)
        }
        if (iflag == 1 && oflag == -1) {
                /* command + 1 byte input: read byte op. */
-               c.rbuf = ibuf;
-               c.rcount = iflag;
                if (ioctl(fd, SMB_READB, &c) == -1)
                        return (-1);
-               printf(fmt, (int)(unsigned char)ibuf[0]);
+               printf(fmt, (unsigned char)c.rdata.byte);
                putchar('\n');
                return (0);
        } else if (iflag == -1 && oflag == 1) {
@@ -176,11 +176,9 @@ do_io(void)
                return (ioctl(fd, SMB_WRITEB, &c));
        } else if (wflag && iflag == 2 && oflag == -1) {
                /* command + 2 bytes input: read word op. */
-               c.rbuf = (char*) &iword;
-               c.rcount = iflag;
                if (ioctl(fd, SMB_READW, &c) == -1)
                        return (-1);
-               printf(fmt, (int)(unsigned short)iword);
+               printf(fmt, (unsigned short)c.rdata.word);
                putchar('\n');
                return (0);
        } else if (wflag && iflag == -1 && oflag == 2) {
@@ -193,11 +191,9 @@ do_io(void)
                 * "process call" op.
                 */
                c.wdata.word = oword;
-               c.rbuf = (char*) &iword;
-               c.rcount = iflag;
                if (ioctl(fd, SMB_PCALL, &c) == -1)
                        return (-1);
-               printf(fmt, (int)(unsigned short)iword);
+               printf(fmt, (unsigned short)c.rdata.word);
                putchar('\n');
                return (0);
        } else if (iflag > 1 && oflag == -1) {
@@ -206,7 +202,7 @@ do_io(void)
                c.rcount = iflag;
                if (ioctl(fd, SMB_BREAD, &c) == -1)
                        return (-1);
-               for (i = 0; i < iflag; i++) {
+               for (i = 0; i < c.rcount; i++) {
                        if (i != 0)
                                putchar(' ');
                        printf(fmt, ibuf[i]);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to