I am using a C program open(), close(), read(), write()
technique to copy a large file to RAW disk. The disk size is 20 GB and the file size is 17 GB but, every time after around writing 945 MB write()
throws No space left on device
error.
I have run fdisk -l /dev/sdb
and returns 20.5 GB and du /dev/sdb
says 945126569
Then I tried, cat mylargefile > /dev/sdb
it too throws same No space left on device
error and then I do cat /dev/sdb > /tmp/sdb.img
it completes normally. Then I do ls -ld /tmp/sdb.img
it responds 945126569
I can use the same disk to create ext4
file system and format it without any issues, so disk error is improbable. (I guess ...)
I am using Ubuntu 16.04 LTS amd64 OS with latest GCC to build my program.
Can anyone suggest where am I going wrong or what needs to be done to avoid this?