> I'd like to create a mechanism by which a kernel driver can "poll" on media
> changes on USB removeable media, such as:
>
> - floppy ejection
> - memory stick unplugs
Hmm, an USB memory stick has fixed media. It's the scsa2usb
driver that pretends the usb storage device is a removable media
device.
An USB floppy, USB zip or USB CD/DVD device would be examples
of real USB removable media devices.
I think the cases "media is removed from a removable media device"
and "usb storage device is hot-removed" are quite different.
> The problem I have is that DKIOCSTATE, as per
> dkio(7d), blocks:
>
> DKIOCSTATE
> This ioctl() blocks until the state of the drive,
> inserted or ejected, is changed. The argument is a
> [ ... ]
The way I understand it is, that it returns when the current
media state (ejected or inserted) is different from the one
passed as argument to the DKIOCSTATE ioctl.
So, if you pass a current state of "DKIO_NONE", the
DKIOCSTATE ioctl should return the disk's current state,
without blocking. I've used the test program included below
to experiment with this.
Problem is that the (x86) ps/2 floppy driver does block
on the second poll when no media is inserted in the drive.
Bug in the fd driver's DKIOCSTATE / DKIO_NONE
implementation?
And with a hot removed usb storage device that is still in use,
it continues to return "DKIO_INSERTED" . scsa2usb is waiting
for the busy device to be re-connected; and when re-connected
device operation resumes and the scsa2usb user doesn't notice
that the device was gone (console messages: "(scsa2usb1):
Disconnected device was busy, please reconnect." and
"(scsa2usb1): Reinserted device is accessible again.")
==================================================
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/dkio.h>
int
main(int argc, char **argv)
{
char *devname = argv[1];
int fd;
int state;
fd = open(devname, O_RDONLY|O_NDELAY);
if (fd < 0) {
perror(devname);
exit(1);
}
state = DKIO_NONE;
if (ioctl(fd, DKIOCSTATE, &state)) {
perror("DKIOCSTATE");
exit(1);
}
switch (state) {
case DKIO_EJECTED:
printf("is ejected\n");
break;
case DKIO_INSERTED:
printf("is inserted\n");
break;
default:
printf("media state %d is unknown\n", state);
break;
}
close(fd);
return 0;
}
This message posted from opensolaris.org
_______________________________________________
opensolaris-discuss mailing list
[email protected]