Scenario:
- Raspberry Pi 3 Model B
- Adaptronic Modular ECU connected via USB (presents itself as a mass storage device, well 2 actually, sda and sdb in this case)
I'm simply using fopen() to open /dev/sda for reading, I seek to the position I want to read and I read 2048 bytes. I then re-seek to the position I seek'ed before and read that data again.
On my first read, I get fresh, correct data. On each subsequent read I get the same data over and over again. It does not attempt to poll the device again (because it has an activity light) after the first read, however when I kill my app (ctrl+c) I see the activity light flashing madly and then stop.
I thought it was a buffering issue with my code (I started with ifstream, and have tried fopen() and open(), all the same) and tried the various different methods of disabling the buffing (ie. setvbuf()) but I'm still not getting fresh data.
If I close and open the file again then I get new data but this is a very slow process (I only get about 10-12 samples/sec).
Keep in mind, this is not a mounted device, it simply presents as a storage device and I read from its block device directly.
I ported the same code to Windows and it works, so I don't believe it is my code, but rather something within Linux.
Any help would be greatly appreciated.
int fd = fileno(fp); ioctl(fd, BLKFLSBUF, 0);
which does work but is very slow, possibly as slow or slower than closing and opening the file again. – Josh Finlayecho 3 > /proc/sys/vm/drop_cache
and this works but with severe performance degradation (similar to that of closing/opening the file again) – Josh Finlay