Skip to contentSkip to conversation

raw-posix: Detect IDE floppy via ioctl

PATCH Superseded Cole Robinson 2 participants 3 messages Jan 11, 2010 – Jan 12, 2010 Block layer

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 raw-posix: Detect IDE floppy via ioctl

Current IDE floppy detection is hardcoded based on source file name. Make this smarter by attempting a floppy specific ioctl.

---
 block/raw-posix.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
block/raw-posix.c +18 -1
index 3ec58d0..5d6b9fb 100644
@@ -1055,9 +1055,26 @@ static int floppy_open(BlockDriverState *bs, const char *filename, int flags)
 
 static int floppy_probe_device(const char *filename)
 {
+    int fd, ret;
+    struct floppy_struct fdparam;
+
     if (strstart(filename, "/dev/fd", NULL))
         return 100;
-    return 0;
+
+    fd = open(filename, O_RDONLY | O_NONBLOCK);
+    if (fd < 0) {
+        return 0;
+    }
+
+    /* Attempt to detect via a floppy specific ioctl */
+    if (ioctl(fd, FDGETPRM, &fdparam) < 0 && errno == EINVAL) {
+        ret = 0;
+    } else {
+        ret = 100;
+    }
+
+    close(fd);
+    return ret;
 }
 
 
Signature · 1 line
1.6.6
#1 lore raw
Quoted 2 lines · Cole Robinson

Current IDE floppy detection is hardcoded based on source file name. Make this smarter by attempting a floppy specific ioctl.

IDE floppys show up as /dev/hd?, these are old legacy floppies.

Otherwise looks good except that I think the ioctl should have a higher match priority than the name match. Same applies to the CDROM version of the patch.

#2 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Cole Robinson

Current IDE floppy detection is hardcoded based on source file name. Make this smarter by attempting a floppy specific ioctl.

IDE floppys show up as /dev/hd?, these are old legacy floppies.

Ah, didn't realize there was a difference.

Quoted 3 lines

Otherwise looks good except that I think the ioctl should have a higher match priority than the name match. Same applies to the CDROM version of the patch.

Will do.

Thanks,
Cole