From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8D68C47082 for ; Thu, 3 Jun 2021 13:41:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D173613E7 for ; Thu, 3 Jun 2021 13:41:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D173613E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonal-0002Ta-IJ for qemu-devel@archiver.kernel.org; Thu, 03 Jun 2021 09:40:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXZ-00037z-1J; Thu, 03 Jun 2021 09:37:41 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]:40711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXX-0000Ah-4U; Thu, 03 Jun 2021 09:37:40 -0400 Received: by mail-ed1-x533.google.com with SMTP id t3so7142998edc.7; Thu, 03 Jun 2021 06:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zbEKtWwYtPu17XYhL91Y3v+VjithiK8Jl8+pLNVJebs=; b=mhvapHKuR1ywaKvJavFkXZyniMR3SkGYpBU6Uns9o1ZmhTM+GwWsgUu39pQqCvF4R8 pxIAm/La2sUFscOGIn7vgheBBNuZcjeF1nw5YqEnggkYiPh5Paw5q8GYXlXVq5Pz1wyq oTRuzQgUqkVRjxdyCZyi7w2EqVEWyiDvn7DFf7E+q7KyVQOCh3k8dDzcPtwrA2MRGEoD DiYjeZ6Is0PCuYmbWe7PT402K587K40y1h/7OTNpGvu1fKNgVmRQkYZOBUZLEGZI7m2b EbvILEM3X1Q0HCe0DNaaaOTMgVp09lanjn3cZ7pPmIVvsCnA6zSRWKjr7kaTrHN/6fIQ eoUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=zbEKtWwYtPu17XYhL91Y3v+VjithiK8Jl8+pLNVJebs=; b=WMDOZXfK3ZK1kh+JWUShzhsq71pGw1FFP0Ukpa6Mi3GtsS0lyT4FFDYonODw4RK83X pC2J8ycvdOsaKyg7rp06LeE8fB1/kM8HMv07lYx731alTymEKN3LtwOW2KlertHwULFS F+b9b1cbOtnIhaB8tc3ffFKWZSMdznmOSInRGlt41Ov4gxQ7+ZBW2fvM4pDJqJ4nfwA3 QqMn1OFFIsAk61rrqzuzAcMGlRnFZUtJ4J+Xcz01i22sD0/I9wMQSss4Wif1w6wNaQcK J0o8k2OchSEbXW3qR+VFCQy7nf6wlFyBmT3evdYWZMDrbAvU+WH/mfvpGJwPvH4qzUe+ nCRw== X-Gm-Message-State: AOAM530sT+FVgrAA5ctbfM7pBmffUW1rRSy6RR3N8bLys/nqB2gX8HdS ZKmTMCZzETI7dwms05zEigjJYcAJTW5+/g== X-Google-Smtp-Source: ABdhPJzUPLjoEg1MNh1ia7sNM9vnPIzltpdI9w7CIxkxY1zHcxxPXfchpL+LZYNpe65eN9SEX3N8Gg== X-Received: by 2002:a05:6402:4310:: with SMTP id m16mr43878029edc.279.1622727457527; Thu, 03 Jun 2021 06:37:37 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 7/7] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Thu, 3 Jun 2021 15:37:22 +0200 Message-Id: <20210603133722.218465-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x533.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Warner Losh , Joelle van Dyne , qemu-block@nongnu.org, Peter Maydell Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Joelle van Dyne iOS hosts do not have these defined so we fallback to the default behaviour. Co-authored-by: Warner Losh Reviewed-by: Peter Maydell Signed-off-by: Joelle van Dyne Message-Id: <20210315180341.31638-4-j@getutm.app> Signed-off-by: Paolo Bonzini --- block/file-posix.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 5821e1afed..4e2f7cf508 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2322,8 +2322,11 @@ static int64_t raw_getlength(BlockDriverState *bs) again: #endif if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) { + size = 0; #ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) { + size = 0; + } #elif defined(DIOCGPART) { struct partinfo pi; @@ -2332,9 +2335,7 @@ again: else size = 0; } - if (size == 0) -#endif -#if defined(__APPLE__) && defined(__MACH__) +#elif defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE) { uint64_t sectors = 0; uint32_t sector_size = 0; @@ -2342,19 +2343,15 @@ again: 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); +#endif + if (size == 0) { + size = lseek(fd, 0LL, SEEK_END); + } if (size < 0) { return -errno; } -#endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) switch(s->type) { case FTYPE_CD: -- 2.31.1