From owner-svn-src-head@freebsd.org Fri Nov 11 15:00:15 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 14635C3B1B3; Fri, 11 Nov 2016 15:00:15 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C234A1149; Fri, 11 Nov 2016 15:00:14 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uABF0ERZ075962; Fri, 11 Nov 2016 15:00:14 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABF0Eqi075961; Fri, 11 Nov 2016 15:00:14 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201611111500.uABF0Eqi075961@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Fri, 11 Nov 2016 15:00:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308528 - head/usr.sbin/smbmsg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 15:00:15 -0000 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]);