kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: j.neuschaefer@gmx.net (Jonathan Neuschäfer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: How to implement a driver's read and write operations with synchronization properly
Date: Tue, 29 Jul 2014 14:47:58 +0200	[thread overview]
Message-ID: <20140729124758.GJ3694@debian> (raw)
In-Reply-To: <CAPmaJ=A3p1s+Ds_jVLAF6xobc04dEp6xAYkTCrWncx1WmTc3Zw@mail.gmail.com>

On Tue, Jul 29, 2014 at 07:15:08PM +0700, Anh Le wrote:
[...]
> I tried the following command: echo $(perl -e "print 'a'x2000") > /dev/sample
> and get the following messages from dmesg:
> [30884.066433] [sample] buf len: 1008, *ppos: 0
> [30884.066451] [sample] buf len: 993, *ppos: 1008
> 
> So as I understand my 2001 bytes has been split into 2 chunks, the
> first one with 1008 bytes and the second one with 993 bytes, and
> therefore the write operation is called 2 times to consume the whole
> input.

I've tried this out myself, and it seems to be an issue with bash:

	$ cat /tmp/aaaa.sh
	#!/bin/sh
	echo aaaaaaa...[trimmed to fit in an e-mail]...aaaaaaa
	$ strace -e trace=write /tmp/aaaa.sh > /dev/null
	write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2001) = 2001
	+++ exited with 0 +++
	$ strace -e trace=write bash /tmp/aaaa.sh > /dev/null
	write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 1008) = 1008
	write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 993) = 993
	+++ exited with 0 +++

[ My default shell, /bin/sh, is Debian's dash. ]

As you can see, I observed the same pattern of 1008 and 993 bytes.


Greetings,
Jonathan Neusch?fer

  parent reply	other threads:[~2014-07-29 12:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 12:15 How to implement a driver's read and write operations with synchronization properly Anh Le
2014-07-29 12:33 ` Pranay Srivastava
2014-07-29 12:47 ` Jonathan Neuschäfer [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-07-29 13:59 Anh Le
2014-07-29 14:24 ` Valdis.Kletnieks at vt.edu
2014-07-29 18:49   ` Jonathan Neuschäfer
2014-07-29  8:03 Anh Le
2014-07-29  8:36 ` Jonathan Neuschäfer
2014-07-29 11:59 ` Pranay Srivastava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140729124758.GJ3694@debian \
    --to=j.neuschaefer@gmx.net \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).