<p dir="ltr"><br>
On 29-Jul-2014 5:54 PM, "Anh Le" <<a href="mailto:anhlq2110@gmail.com">anhlq2110@gmail.com</a>> wrote:<br>
><br>
> Thanks, Jonathan, for the quick reply.<br>
><br>
> On Tue, Jul 29, 2014 at 3:36 PM, Jonathan Neuschäfer<br>
> <<a href="mailto:j.neuschaefer@gmx.net">j.neuschaefer@gmx.net</a>> wrote:<br>
> > Which "write operation" is called twice in your scenario?<br>
><br>
> It's the "write" method of the "struct file_operations" structure. I<br>
> define it like this (no synchronizatin yet):<br>
> static ssize_t sample_write(struct file *f, const char __user *buf,<br>
> size_t len, loff_t *ppos)<br>
> {<br>
> printk(KERN_DEBUG "[sample] buf len: %u, *ppos: %u\n", len, *ppos);<br>
> return simple_write_to_buffer(kbuf, 2048, ppos, buf, len);<br>
> }<br>
><br>
> > If a userspace program writes 1000 bytes at first, how can you know that<br>
> > it wants to perform another write later on?<br>
><br>
> I use printk to debug the module. More details in the answer below.<br>
><br>
> > If a userspace program wants to write a chunk of data atomically, it<br>
> > should use just one call to write(2). (On Linux, one can save some<br>
> > copying by using writev(2), which writes data from multiple buffers in<br>
> > one atomic step.)<br>
><br>
> I tried the following command: echo $(perl -e "print 'a'x2000") > /dev/sample<br>
> and get the following messages from dmesg:<br>
> [30884.066433] [sample] buf len: 1008, *ppos: 0<br>
> [30884.066451] [sample] buf len: 993, *ppos: 1008<br>
><br>
> So as I understand my 2001 bytes has been split into 2 chunks, the</p>
<p dir="ltr">Who do you think did this split? I would say write a simple program and do only a single write syscall for your buffer size. Just see if that split happens again.</p>
<p dir="ltr">> first one with 1008 bytes and the second one with 993 bytes, and<br>
> therefore the write operation is called 2 times to consume the whole<br>
> input.<br>
><br>
> --<br>
> Le Quoc Anh<br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</p>