Floppy disk change detection in 2.4.19 and 2.5.45...

From: Petr Vandrovec (VANDROVE@vc.cvut.cz)
Date: Mon Nov 04 2002 - 16:21:58 EST


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;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Nov 07 2002 - 22:00:34 EST