From mboxrd@z Thu Jan 1 00:00:00 1970 From: j.neuschaefer@gmx.net (Jonathan =?utf-8?Q?Neusch=C3=A4fer?=) Date: Tue, 29 Jul 2014 14:47:58 +0200 Subject: How to implement a driver's read and write operations with synchronization properly In-Reply-To: References: Message-ID: <20140729124758.GJ3694@debian> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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