I have an application running on an embedded computer. The user may plug in a USB flash memory and try to access it. I would like to give an error message immediately if the user tries to write to a write-protected memory, but haven't figured out how. For example, I tried
Code:
i = open(file_name, O_WRONLY | O_CREAT | O_SYNC);
if (i < 0)
perror("open");
else
{
j = write(i, &i, 4);
if (j != 4)
perror("write");
close(i);
}
on a write protected memory, but it gave no immediate error. I can even remove the USB memory, and then fopen, fwrite, and fclose a file with no error reported to the application. The console terminal gets pelted with error messages, though.
It's an older computer, so it has Linux kernel 2.4.26 with libc 2.3.2.