From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZawCL-0004cA-4F for qemu-devel@nongnu.org; Sat, 12 Sep 2015 21:35:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZawCH-0001v0-RM for qemu-devel@nongnu.org; Sat, 12 Sep 2015 21:35:17 -0400 From: Programmingkid Content-Type: multipart/alternative; boundary=Apple-Mail-1--55557131 Date: Sat, 12 Sep 2015 21:35:10 -0400 Message-Id: <3B76BBCC-8E49-4D02-AF9C-4D952099A0CF@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] ping: [PATCH v5] raw-posix.c: Make physical devices usable in QEMU under Mac OS X host List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-devel qemu-devel Cc: Qemu-block --Apple-Mail-1--55557131 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > Mac OS X can be picky when it comes to allowing the user to use = physical devices > in QEMU. Most mounted volumes appear to be off limits to QEMU. If an = issue is > detected, a message is displayed showing the user how to unmount a = volume. >=20 > Signed-off-by: John Arbuckle >=20 > --- > Removed changes to GetBSDPath() to a separate patch. > This patch now depends on the GetBSDPath patch. >=20 > block/raw-posix.c | 90 = +++++++++++++++++++++++++++++++++++++--------------- > 1 files changed, 64 insertions(+), 26 deletions(-) >=20 > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 67d1d48..a41006f 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -42,9 +42,8 @@ > #include > #include > #include > -//#include > #include > -#endif > +#endif /* (__APPLE__) && (__MACH__) */ > =20 > #ifdef __sun__ > #define _POSIX_PTHREAD_SEMANTICS 1 > @@ -1972,7 +1971,7 @@ BlockDriver bdrv_file =3D { > /* host device */ > =20 > #if defined(__APPLE__) && defined(__MACH__) > -static kern_return_t FindEjectableCDMedia( io_iterator_t = *mediaIterator ); > +static kern_return_t FindEjectableCDMedia(io_iterator_t = *mediaIterator); > static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char = *bsdPath, > CFIndex maxPathSize, int flags); > kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator ) > @@ -2030,7 +2029,34 @@ kern_return_t GetBSDPath(io_iterator_t = mediaIterator, char *bsdPath, > return kernResult; > } > =20 > -#endif > +/* Sets up a real cdrom for use in QEMU */ > +static bool setupCDROM(char *bsdPath) > +{ > + int index, numOfTestPartitions =3D 2, fd; > + char testPartition[MAXPATHLEN]; > + bool partitionFound =3D false; > + > + /* look for a working partition */ > + for (index =3D 0; index < numOfTestPartitions; index++) { > + snprintf(testPartition, sizeof(testPartition), "%ss%d", = bsdPath, index); > + fd =3D qemu_open(testPartition, O_RDONLY | O_BINARY | = O_LARGEFILE); > + if (fd >=3D 0) { > + partitionFound =3D true; > + qemu_close(fd); > + break; > + } > + } > + > + /* if a working partition on the device was not found */ > + if (partitionFound =3D=3D false) { > + printf("Error: Failed to find a working partition on = disc!\n"); > + } else { > + DPRINTF("Using %s as optical disc\n", testPartition); > + pstrcpy(bsdPath, MAXPATHLEN, testPartition); > + } > + return partitionFound; > +} > +#endif /* defined(__APPLE__) && defined(__MACH__) */ > =20 > static int hdev_probe_device(const char *filename) > { > @@ -2118,34 +2144,32 @@ static int hdev_open(BlockDriverState *bs, = QDict *options, int flags, > BDRVRawState *s =3D bs->opaque; > Error *local_err =3D NULL; > int ret; > + bool cdromOK =3D true; > =20 > #if defined(__APPLE__) && defined(__MACH__) > const char *filename =3D qdict_get_str(options, "filename"); > =20 > - if (strstart(filename, "/dev/cdrom", NULL)) { > - kern_return_t kernResult; > - io_iterator_t mediaIterator; > - char bsdPath[ MAXPATHLEN ]; > - int fd; > - > - kernResult =3D FindEjectableCDMedia( &mediaIterator ); > - kernResult =3D GetBSDPath(mediaIterator, bsdPath, = sizeof(bsdPath),=20 > - = flags); > - if ( bsdPath[ 0 ] !=3D '\0' ) { > - strcat(bsdPath,"s0"); > - /* some CDs don't have a partition 0 */ > - fd =3D qemu_open(bsdPath, O_RDONLY | O_BINARY | = O_LARGEFILE); > - if (fd < 0) { > - bsdPath[strlen(bsdPath)-1] =3D '1'; > + /* If using a physical device */ > + if (strstart(filename, "/dev/", NULL)) { > + char bsdPath[MAXPATHLEN]; > + > + /* If the physical device is a cdrom */ > + if (strcmp(filename, "/dev/cdrom") =3D=3D 0) { > + io_iterator_t mediaIterator; > + FindEjectableCDMedia(&mediaIterator); > + GetBSDPath(mediaIterator, bsdPath, sizeof(bsdPath), = flags); > + if (bsdPath[0] =3D=3D '\0') { > + printf("Error: failed to obtain bsd path for optical = drive!\n"); > } else { > - qemu_close(fd); > + cdromOK =3D setupCDROM(bsdPath); > + filename =3D bsdPath; > } > - filename =3D bsdPath; > - qdict_put(options, "filename", = qstring_from_str(filename)); > - } > =20 > - if ( mediaIterator ) > - IOObjectRelease( mediaIterator ); > + if (mediaIterator) { > + IOObjectRelease(mediaIterator); > + } > + } > + qdict_put(options, "filename", qstring_from_str(filename)); > } > #endif > =20 > @@ -2156,7 +2180,21 @@ static int hdev_open(BlockDriverState *bs, = QDict *options, int flags, > if (local_err) { > error_propagate(errp, local_err); > } > - return ret; > + } > + > +#if defined(__APPLE__) && defined(__MACH__) > + /* if a physical device experienced an error while being opened = */ > + if (strncmp(filename, "/dev/", 5) =3D=3D 0 && (cdromOK =3D=3D = false || ret !=3D 0)) { > + printf("If device %s is mounted on the desktop, unmount it" > + " first before using it in QEMU.\n", = filename); > + printf("Command to unmount device: diskutil unmountDisk = %s\n", > + = filename); > + printf("Command to mount device: diskutil mountDisk %s\n", = filename); > + } > +#endif /* defined(__APPLE__) && defined(__MACH__) */ > + > + if (ret < 0) { > + return ret; > } > =20 > /* Since this does ioctl the device must be already opened */ > --=20 > 1.7.5.4 I would like to know that status of this patch please.=20= --Apple-Mail-1--55557131 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Mac OS X can be picky when it comes = to allowing the user to use physical devices
in = QEMU. Most mounted volumes appear to be off limits to QEMU. If an issue = is

Signed-off-by: John Arbuckle = <programmingkidx@gmail.com>= ;

---
Removed changes to = GetBSDPath() to a separate patch.
This patch now depends on the = GetBSDPath patch.

 block/raw-posix.c | =   90 +++++++++++++++++++++++++++++++++++++---------------

diff --git a/block/raw-posix.c = b/block/raw-posix.c
index 67d1d48..a41006f 100644
--- = a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ = -42,9 +42,8 @@
 #include = <IOKit/storage/IOMediaBSDClient.h>
 #include = <IOKit/storage/IOMedia.h>
 #include = <IOKit/storage/IOCDMedia.h>
-//#include = <IOKit/storage/IOCDTypes.h>
 #include = <CoreFoundation/CoreFoundation.h>
-#endif
 
 #ifdef __sun__
@@ -1972,7 +1971,7 @@ = BlockDriver bdrv_file =3D {
 /* host device */
 
 #if defined(__APPLE__) = && defined(__MACH__)
-static kern_return_t = FindEjectableCDMedia( io_iterator_t *mediaIterator );
 static kern_return_t GetBSDPath(io_iterator_t = mediaIterator, char *bsdPath,
         =                     =     CFIndex maxPathSize, int flags);
     return = kernResult;
 }
 
-#endif
+/* Sets up a real cdrom for = use in QEMU */
+static bool setupCDROM(char *bsdPath)
+    int index, numOfTestPartitions =3D = 2, fd;
+    char = testPartition[MAXPATHLEN];
+    bool partitionFound =3D = false;
+
+    /* look for a working partition = */
+        = snprintf(testPartition, sizeof(testPartition), "%ss%d", bsdPath, = index);
+        fd =3D = qemu_open(testPartition, O_RDONLY | O_BINARY | O_LARGEFILE);
+            = qemu_close(fd);
+            = break;
+        }
+
+    /* if a working partition on the = device was not found */
+    if (partitionFound =3D=3D= false) {
+        printf("Error: Failed = to find a working partition on disc!\n");
+    } else = {
+        pstrcpy(bsdPath, = MAXPATHLEN, testPartition);
+    }
+}
 
 static int = hdev_probe_device(const char *filename)
 {
@@ = -2118,34 +2144,32 @@ static int hdev_open(BlockDriverState *bs, QDict = *options, int flags,
     BDRVRawState *s =3D = bs->opaque;
     Error *local_err =3D = NULL;
     int ret;
 
 #if defined(__APPLE__) = && defined(__MACH__)
     const char = *filename =3D qdict_get_str(options, "filename");
 
-    if (strstart(filename, = "/dev/cdrom", NULL)) {
-        kern_return_t = kernResult;
-        io_iterator_t = mediaIterator;
-        char bsdPath[ = MAXPATHLEN ];
-        int fd;
-        kernResult =3D = FindEjectableCDMedia( &mediaIterator );
-        = kernResult =3D GetBSDPath(mediaIterator, bsdPath, = sizeof(bsdPath), 
-              =                     =                     =                   = flags);
-        if ( bsdPath[ 0 ] !=3D = '\0' ) {
-            = strcat(bsdPath,"s0");
-            /* some = CDs don't have a partition 0 */
-          =   fd =3D qemu_open(bsdPath, O_RDONLY | O_BINARY | = O_LARGEFILE);
-            if (fd = < 0) {
-              =   bsdPath[strlen(bsdPath)-1] =3D '1';
+    /* If using a = physical device */
+    if (strstart(filename, "/dev/", = NULL)) {
+        char = bsdPath[MAXPATHLEN];
+
+        /* If the physical = device is a cdrom */
+        if (strcmp(filename, = "/dev/cdrom") =3D=3D 0) {
+          =   io_iterator_t mediaIterator;
+          =   FindEjectableCDMedia(&mediaIterator);
+          =   if (bsdPath[0] =3D=3D '\0') {
+          =       printf("Error: failed to obtain bsd path for = optical drive!\n");
             } = else {
-              =   qemu_close(fd);
+              =   cdromOK =3D setupCDROM(bsdPath);
+        =         filename =3D bsdPath;
-            = qdict_put(options, "filename", qstring_from_str(filename));
 
-        if ( = mediaIterator )
-            = IOObjectRelease( mediaIterator );
+          =   if (mediaIterator) {
+          =       IOObjectRelease(mediaIterator);
+        = qdict_put(options, "filename", qstring_from_str(filename));
 #endif
 
@@ -2156,7 +2180,21 @@ static int = hdev_open(BlockDriverState *bs, QDict *options, int flags,
         }
+    }
+#if defined(__APPLE__) && = defined(__MACH__)
+    /* if a physical device experienced = an error while being opened */
+    if (strncmp(filename, = "/dev/", 5) =3D=3D 0 && (cdromOK =3D=3D false || ret !=3D 0)) = {
+              =           " first before using it in QEMU.\n", = filename);
+        printf("Command to = unmount device: diskutil unmountDisk %s\n",
+        =                     =                     =                     = filename);
+        printf("Command to = mount device: diskutil mountDisk %s\n", filename);
+#endif /* defined(__APPLE__) && = defined(__MACH__) */
+
+    if (ret < 0) {
+ =       return ret;
     }
 
     /* Since this = does ioctl the device must be already opened */
1.7.5.4

I = would like to know that status of this patch = please. 
= --Apple-Mail-1--55557131--