user buffer after doing 'write' to file opened with O_DIRECT
Posted
by
user1868481
on Stack Overflow
See other posts from Stack Overflow
or by user1868481
Published on 2012-12-01T10:59:08Z
Indexed on
2012/12/01
11:03 UTC
Read the original article
Hit count: 160
I'm using the O_DIRECT
flag to write to the disk directly from the user buffer.
But as far as I understand, Linux doesn't guarantee that after this call, the data is written.
It just writes directly from the user buffer to the physical device using DMA or anything else...
Therefore, I don't understand if I can write to the user buffer after the call to 'write' function.
I'm sure that example code will help to understand my question:
char *user_buff = malloc(...); /* assume it is aligned as needed */
fd = open(..., O_DIRECT);
write(fd, ...)
memset(user_buff, 0, ...)
Is the last line (memset) legal? Is writing to the user buffer valid that is maybe used by DMA to transfer data to the device?
© Stack Overflow or respective owner