Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jun 2009 20:32:01 +0200
From:      Juergen Lock <nox@jelal.kn-bremen.de>
To:        freebsd-emulation@FreeBSD.org
Subject:   VBoxManage physical disk size patch
Message-ID:  <20090608183201.GA20790@triton.kn-bremen.de>

next in thread | raw e-mail | index | archive | help
I wanted to pass a physical disk to vbox today as per this info,
	http://www.virtualbox.org/manual/UserManual.html#rawdisk
and found out there is code missing to get the size of physical disks
in VBoxManage; the following patch seems to work for me:

Index: src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
@@ -54,7 +54,8 @@
 #ifdef RT_OS_WINDOWS
 # include <windows.h>
 # include <winioctl.h>
-#elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) \
+    || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 # include <errno.h>
 # include <sys/ioctl.h>
 # include <sys/types.h>
@@ -76,6 +77,9 @@
 # include <sys/dkio.h>
 # include <sys/vtoc.h>
 #endif /* RT_OS_SOLARIS */
+#ifdef RT_OS_FREEBSD
+# include <sys/disk.h>
+#endif /* RT_OS_FREEBSD */
 
 using namespace com;
 
@@ -1010,6 +1014,28 @@
         vrc = VERR_INVALID_PARAMETER;
         goto out;
     }
+#elif defined(RT_OS_FREEBSD)
+    struct stat DevStat;
+    if (!fstat(RawFile, &DevStat) && S_ISCHR(DevStat.st_mode))
+    {
+        off_t cMediasize = 0;
+        if (!ioctl(RawFile, DIOCGMEDIASIZE, &cMediasize))
+        {
+            cbSize = cMediasize;
+        }
+        else
+        {
+            vrc = RTErrConvertFromErrno(errno);
+            RTPrintf("Cannot get the block count for file '%s': %Rrc", rawdisk.raw(), vrc);
+            goto out;
+        }
+    }
+    else
+    {
+        RTPrintf("File '%s' is no character device\n", rawdisk.raw());
+        vrc = VERR_INVALID_PARAMETER;
+        goto out;
+    }
 #else /* all unrecognized OSes */
     /* Hopefully this works on all other hosts. If it doesn't, it'll just fail
      * creating the VMDK, so no real harm done. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090608183201.GA20790>