How to implement a driver's read and write operations with synchronization properly

Jonathan Neuschäfer j.neuschaefer at gmx.net
Tue Jul 29 08:47:58 EDT 2014


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



More information about the Kernelnewbies mailing list