From patchwork Sun Dec 28 21:18:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 424341 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1B6121400D2 for ; Mon, 29 Dec 2014 08:19:07 +1100 (AEDT) Received: from localhost ([::1]:59464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5LEr-0003le-QN for incoming@patchwork.ozlabs.org; Sun, 28 Dec 2014 16:19:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5LEb-0003CI-Ae for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5LEY-0002De-34 for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:45 -0500 Received: from mail-qc0-x234.google.com ([2607:f8b0:400d:c01::234]:64251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5LEX-0002DV-Ur for qemu-devel@nongnu.org; Sun, 28 Dec 2014 16:18:42 -0500 Received: by mail-qc0-f180.google.com with SMTP id i8so8621840qcq.25 for ; Sun, 28 Dec 2014 13:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; bh=qj/bHJlw757CPZo7tOpCYVlyp3Felthcc6At9oZ2zSU=; b=oZ0OB0bEa+PnvLwPwxkyc9ALpWm1tM9k5NijcI53Mb0i0jwtZ7NJiI2uunBtamzOFd ajEd0YCVbzP/8M8S5EBwjQKF5f1hQeCT7M/EFVxy+IzzenzUc0z1JfkzbW2LzIcOGVgr OzaGvZZHPLSFonEgltImUVxpK7hGlAatj5ubdby7xkhMy8H+UG5EufPw/scNJF55v9NJ 2NZdCHYeslPKEBnPG8YmnsWcaZuDmKu9wqFkJfyQvkJEvGRZyLUh2NqHXwsc9Ud0esQA yMcszB17CuOBKqRXgyx54rKBhWNfTvO3ONMTi8ig3oLbZj+FLL2Cq8kHKOM4c4px1p14 z9zA== X-Received: by 10.224.172.198 with SMTP id m6mr11506536qaz.11.1419801521365; Sun, 28 Dec 2014 13:18:41 -0800 (PST) Received: from [192.168.0.2] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by mx.google.com with ESMTPSA id r2sm6176143qah.1.2014.12.28.13.18.40 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Dec 2014 13:18:40 -0800 (PST) From: Programmingkid Date: Sun, 28 Dec 2014 16:18:38 -0500 Message-Id: <96FCDECA-CC6E-4E30-A812-40FA3CA78C31@gmail.com> To: qemu-devel qemu-devel Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::234 Cc: Kevin Wolf , Peter Maydell Subject: [Qemu-devel] [PATCH v3] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch fixes the problem with raw_getlength() on Mac OS X so that it actually calculates the correct size of a volume. It has been updated to fix certain coding style issues. Booting and using a real CD in QEMU works again. signed-off-by: John Arbuckle Reviewed-by: Peter Maydell --- block/raw-posix.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..a090c9c 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,24 @@ again: if (size == 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size = LLONG_MAX; + { + uint64_t sectors = 0; + uint32_t sectorSize = 0; + int ret; + + /* Query the number of sectors on the disk */ + ret = ioctl(fd, DKIOCGETBLOCKCOUNT, §ors); + if (ret == -1) { + return -errno; + } + + /* Query the size of each sector */ + ret = ioctl(fd, DKIOCGETBLOCKSIZE, §orSize); + if (ret == -1) { + return -errno; + } + size = sectors * sectorSize; + } #else size = lseek(fd, 0LL, SEEK_END); if (size < 0) {