From owner-freebsd-emulation@FreeBSD.ORG Mon Jun 8 18:40:14 2009 Return-Path: Delivered-To: freebsd-emulation@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA4C5106566B for ; Mon, 8 Jun 2009 18:40:14 +0000 (UTC) (envelope-from nox@jelal.kn-bremen.de) Received: from smtp.kn-bremen.de (gelbbaer.kn-bremen.de [78.46.108.116]) by mx1.freebsd.org (Postfix) with ESMTP id AABD08FC08 for ; Mon, 8 Jun 2009 18:40:14 +0000 (UTC) (envelope-from nox@jelal.kn-bremen.de) Received: by smtp.kn-bremen.de (Postfix, from userid 10) id 651F61E001E0; Mon, 8 Jun 2009 20:40:13 +0200 (CEST) Received: from triton.kn-bremen.de (noident@localhost [127.0.0.1]) by triton.kn-bremen.de (8.14.3/8.14.3) with ESMTP id n58IW2SZ020803 for ; Mon, 8 Jun 2009 20:32:02 +0200 (CEST) (envelope-from nox@triton.kn-bremen.de) Received: (from nox@localhost) by triton.kn-bremen.de (8.14.3/8.14.3/Submit) id n58IW2MR020802 for freebsd-emulation@FreeBSD.org; Mon, 8 Jun 2009 20:32:02 +0200 (CEST) (envelope-from nox) From: Juergen Lock Date: Mon, 8 Jun 2009 20:32:01 +0200 To: freebsd-emulation@FreeBSD.org Message-ID: <20090608183201.GA20790@triton.kn-bremen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Cc: Subject: VBoxManage physical disk size patch X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2009 18:40:15 -0000 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 # include -#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 # include # include @@ -76,6 +77,9 @@ # include # include #endif /* RT_OS_SOLARIS */ +#ifdef RT_OS_FREEBSD +# include +#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. */