From: "Petr Vandrovec" <VANDROVE@vc.cvut.cz>
To: linux-kernel@vger.kernel.org
Subject: Floppy disk change detection in 2.4.19 and 2.5.45...
Date: Mon, 4 Nov 2002 23:21:58 +0200 [thread overview]
Message-ID: <6962D7F5148@vcnet.vc.cvut.cz> (raw)
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;
}
reply other threads:[~2002-11-04 22:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6962D7F5148@vcnet.vc.cvut.cz \
--to=vandrove@vc.cvut.cz \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®