From patchwork Sun Dec 28 00:36:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 424268 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 D65D81400D2 for ; Sun, 28 Dec 2014 11:36:44 +1100 (AEDT) Received: from localhost ([::1]:57276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y51qZ-0006cK-Vv for incoming@patchwork.ozlabs.org; Sat, 27 Dec 2014 19:36:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y51qJ-0006KE-Gt for qemu-devel@nongnu.org; Sat, 27 Dec 2014 19:36:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y51qG-00086q-CA for qemu-devel@nongnu.org; Sat, 27 Dec 2014 19:36:23 -0500 Received: from mail-qa0-x231.google.com ([2607:f8b0:400d:c00::231]:62964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y51qG-00086l-7i for qemu-devel@nongnu.org; Sat, 27 Dec 2014 19:36:20 -0500 Received: by mail-qa0-f49.google.com with SMTP id dc16so7976278qab.22 for ; Sat, 27 Dec 2014 16:36:19 -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 :to:mime-version; bh=nLPwBc5fhME5UyimTKgLVxMji5NNptgpr2g55hN+U/4=; b=PwQlpGMsmA4JEO0oDn2D69WIjIdWjVHv/h3wg4eTMr8+gn53sp5bGuUn32DX0vPX4S EW3vh/NKk5mau2KheCOFuzkyO9NYAz+zjuw4nean3qKJxvV1zmlYZu8PD4tzR3WLdoit NmadwCrG48dvWR9/Kbl1oPG0xZk4nmtmF8PyYoVFNwJc3jQmQbfwHqv0SzTJdP1e1X7d wtk6SSLfk0AchJI+Ut67zs7U6yLTFc6uB/n5it+haOZzWp2rudyilBOZLDNFvVu+//wH Z6bKELoLSbs3VT6sBiGzdHeFJ490QgSFxsd+aBVgHBz2m2hCDYb/C8ZXj7ymth2qP7/v aVSA== X-Received: by 10.140.21.106 with SMTP id 97mr75312282qgk.61.1419726978965; Sat, 27 Dec 2014 16:36:18 -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 j9sm6837484qao.16.2014.12.27.16.36.17 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 27 Dec 2014 16:36:18 -0800 (PST) From: Programmingkid Date: Sat, 27 Dec 2014 19:36:16 -0500 Message-Id: <6392322B-686D-496A-9E66-30C9F962355D@gmail.com> To: Kevin Wolf , 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:c00::231 Subject: [Qemu-devel] [PATCH] 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 The raw_getlength() function under Mac OS X incorrectly returned a constant value instead of calculating the size of a real CD-ROM disc. This patch fixes this problem and makes booting from a real CD-ROM disc possible again under Mac OS X. signed-off-by: John Arbuckle --- block/raw-posix.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..d723133 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,16 @@ again: if (size == 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size = LLONG_MAX; + // Query the number of sectors on the disk + uint64_t sectors = 0; + ioctl(fd, DKIOCGETBLOCKCOUNT, §ors); + + // Query the size of each sector + uint32_t sectorSize = 0; + ioctl(fd, DKIOCGETBLOCKSIZE, §orSize); + + size = sectors * sectorSize; + //printf("size of disc = %d MB\n", size/(1024*1024)); #else size = lseek(fd, 0LL, SEEK_END); if (size < 0) {