Hi,
when floppy driver changes in 2.3.99 happened, I was told that
if /dev/fd0 is opened with O_EXCL | O_SYNC, read()/write() after
disk change will fail with error, and so app is notified about change.
But today it was pointed to me that this does not work anymore: both
2.4.19 and 2.5.45 do not report disk change when used this way (2.4.5
does). When I use O_EXCL | O_NDELAY, I can detect that disk change
happened since last close, but subsequent disk changes are not reported
to the app, so it is unusable too...
I stared at floppy.c code (in 2.5.45) for an hour, but I cannot find what's
proper way to do that: after disk change I need that read or write fails
(preferred) or that I can call some ioctl() before read/write and this
ioctl will tell me that disk change happened (I did not found such call,
sorry).
Thanks,
Petr Vandrovec
[email protected]
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fd.h>
#include <sys/ioctl.h>
int main(void) {
int fd;
char b[512];
int r;
fd = open("/dev/fd0", O_EXCL | O_SYNC | O_RDWR);
if (fd == -1) {
perror("Open");
return 100;
}
printf("FD opened, %u\n", fd);
r = ioctl(fd, FDCLRPRM, 0);
if (r) {
perror("Error clearing disk change notification");
}
r = read(fd, b, sizeof(b));
if (r == -1) {
perror("Read");
return 99;
}
printf("%u bytes was read\n", r);
getpass("Now replace disk and hit ENTER");
r = read(fd, b, sizeof(b));
if (r == -1) {
perror("Read after disk change failed, ok");
return 0;
}
printf("%u bytes was read, your kernel and/or drive is buggy, or you did not swap diskette\n", r);
close(fd);
return 98;
}