* Floppy disk change detection in 2.4.19 and 2.5.45...
@ 2002-11-04 21:21 Petr Vandrovec
0 siblings, 0 replies; only message in thread
From: Petr Vandrovec @ 2002-11-04 21:21 UTC (permalink / raw)
To: linux-kernel
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
vandrove@vc.cvut.cz
#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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-11-04 22:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-04 21:21 Floppy disk change detection in 2.4.19 and 2.5.45 Petr Vandrovec
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.