From patchwork Mon Jan 19 22:12:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 430716 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 20DF71402AE for ; Tue, 20 Jan 2015 09:13:26 +1100 (AEDT) Received: from localhost ([::1]:40004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDKZX-0000LQ-QI for incoming@patchwork.ozlabs.org; Mon, 19 Jan 2015 17:13:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDKZE-0008Ry-AZ for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:13:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YDKZ9-0004tj-9p for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:13:04 -0500 Received: from mail-qa0-x232.google.com ([2607:f8b0:400d:c00::232]:36573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDKZ9-0004sx-5r for qemu-devel@nongnu.org; Mon, 19 Jan 2015 17:12:59 -0500 Received: by mail-qa0-f50.google.com with SMTP id k15so25950747qaq.9 for ; Mon, 19 Jan 2015 14:12:58 -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=9IMsduQ9Dz2wVG76tZIvs8JIUJoVrNym47agKFcGKs8=; b=VDIzqZl9L4qUt2z7++IXKx4jOwdZBNYiWWNWWO73ful8oxpJHy0fSWWTceVWzrAWit SLlYvhMPIMNL9R17Jqbi32R2/k2RBzzNgIvIEevdPWo15b305/cdQdvoMommuNI9CU7Z MFjW8GjzgXGkEYr11IWLZyIHoKPGFVszK9fUjFpPpY2ntW3der9Ln5FCST1U3Ito8bdG 99lgGawNLFC+RGnRScDRNie9dtnFDy6rpAJV4djhVowDLPyiW1bMBHrSpUd3xi8XH6nd +hoXOSxw7VdwXy7bHWa7+8SlCAwtncXgvLO0deDC57Kxnqn46vfTi9TGxkepBfAQ13m+ 6ODQ== X-Received: by 10.140.46.37 with SMTP id j34mr49289726qga.12.1421705578281; Mon, 19 Jan 2015 14:12:58 -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 j21sm13436678qgd.36.2015.01.19.14.12.56 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Jan 2015 14:12:57 -0800 (PST) From: Programmingkid Date: Mon, 19 Jan 2015 17:12:55 -0500 Message-Id: <2ACCDD16-AFEC-49BF-8BD3-3A3EC55DB2E5@gmail.com> To: Peter Maydell 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::232 Cc: qemu-devel qemu-devel Subject: [Qemu-devel] [PATCH v8] block/raw-posix.c: Fix raw_getlength() on Mac OS X for 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 Subject was: Re: [PATCH v7] block/raw-posix.c: Fixes raw_getlength() on Mac OS X so that it reports the correct length of a real CD This patch allows Mac OS X to use a real CDROM disc in QEMU. Testing this patch will require using QEMU v2.2.0 because the current git version has a bug in it that prevents /dev/cdrom from being used. "make check" did pass and my Debian boot disc did work. Signed-off-by: John Arbuckle Reviewed-by: Stefan Hajnoczi Tested-by: Peter Maydell --- Fixed code indentation to be inline with removed size = LLONG_MAX. block/raw-posix.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..fa431b2 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1312,7 +1312,20 @@ again: if (size == 0) #endif #if defined(__APPLE__) && defined(__MACH__) - size = LLONG_MAX; + { + uint64_t sectors = 0; + uint32_t sector_size = 0; + + if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0 + && ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) { + size = sectors * sector_size; + } else { + size = lseek(fd, 0LL, SEEK_END); + if (size < 0) { + return -errno; + } + } + } #else size = lseek(fd, 0LL, SEEK_END); if (size < 0) {