From owner-freebsd-questions@FreeBSD.ORG Wed Jun 24 21:03:41 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1A771065675 for ; Wed, 24 Jun 2009 21:03:41 +0000 (UTC) (envelope-from naeem_jarral@yahoo.com) Received: from web81101.mail.mud.yahoo.com (web81101.mail.mud.yahoo.com [68.142.199.93]) by mx1.freebsd.org (Postfix) with SMTP id 9DBCE8FC13 for ; Wed, 24 Jun 2009 21:03:41 +0000 (UTC) (envelope-from naeem_jarral@yahoo.com) Received: (qmail 9883 invoked by uid 60001); 24 Jun 2009 20:37:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1245875820; bh=LDPBlbbVuUAgQczE3kdsmgpXJEZvVYhx3HEd9Tdm/cg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=Fwpf313VxAbsMfAJ7Rzznsloe0CLdlqJO4RlRRLHhT/La1F+t4UjtW7WKj2XDC4Ee6QNaQxtogPdWtOJ6ZIpRSVws2PtQD+F9DLYAaG85biwSQDDMZuKKBfx41t7AUL0AIDqYZcPXEze0YqUSvQcA9g5lK32YZXwS0ANezrKLlI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=WlVKgnYGHW0wWIFMhOdq0v+Tg9mCEqpJ43hN/K6AflqLHG1VtEQtsl17PrME8x/eTM86myDx06OqP+E8iJ7s83puylLyExDYoBDPYmgk7dVkA3wNwnIin2Tcm62381Hr7epTBc2RxGfeSw3hVbwhiAt5uf/twdnn1W3xXmT/CJI=; Message-ID: <152120.9119.qm@web81101.mail.mud.yahoo.com> X-YMail-OSG: RMkW9jsVM1mx3lcZPeb.4kr26xsXYmxg6fKZW_EP_US6plbZzsvyILqZ12.gWWq4CfWKbktjPLazhvNSKO074Zg.ZVt1bNdGYluZqXMJHivLaaA4J8SBH_2.KvqtC6mY7MYwuDqWadelQmDIAPghimntIUM_6e90zP5aMVnmLpysvE.M9tMyXUF14yysLs4.FynVQa8PLwlmMDRp5K629PLLvNxkWjWbyRo9TmklA0nJsYXhmFy4KakDVoOE1TZGG3tL0rdI2kwaqOImrx6sU7W_tyYldyOSGvxX43f5IXr86PsH9EXtBmaORYUsmfjuF4xZkfR5_sTjFMKnSCn70wHkYz5zp8pmk7ZDL5rr6w-- Received: from [134.134.139.72] by web81101.mail.mud.yahoo.com via HTTP; Wed, 24 Jun 2009 13:37:00 PDT X-Mailer: YahooMailRC/1277.43 YahooMailWebService/0.7.289.10 Date: Wed, 24 Jun 2009 13:37:00 -0700 (PDT) From: Naeem Afzal To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: echo in sh calls write function repeatedly in kernel driver? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jun 2009 21:03:42 -0000 I used this sample echo driver listed here: http://www.freebsd.org/doc/en/books/arch-handbook/driverbasics-char.html and used Example 9-2 for 5.X FreeBSD. Modifed and added a printline in write function to display Count value: I am using 7.1 FreeBSD version. I compiled the driver and ran the echo command, I see that driver's write function is being called 11 times if I use sh shell? Why is that? If I use bash, then write function is only called once which seems to be correct. Why sh buildin echo is send 11 writes? Any idea? thanks & regards naeem # echo "1234" > /dev/echo Opened device "echo" successfully. Count value: 0 Count value: 1 Count value: 2 Count value: 3 Count value: 4 Count value: 5 Count value: 6 Count value: 7 Count value: 8 Count value: 9 Count value: 10 Closing device "echo." # cat /dev/echo Opened device "echo" successfully. 1234 Closing device "echo." ===== Driver's write function is defined as: static int echo_write(struct cdev *dev, struct uio *uio, int ioflag) { int err = 0; uprintf("Count value: %d\n",count); /* Copy the string in from user memory to kernel memory */ err = copyin(uio->uio_iov->iov_base, echomsg->msg, MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)); /* Now we need to null terminate, then record the length */ *(echomsg->msg + MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)) = 0; echomsg->len = MIN(uio->uio_iov->iov_len, BUFFERSIZE); if (err != 0) { uprintf("Write failed: bad address!\n"); } count++; return(err); }