From nobody Mon Feb 9 05:18:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1615833227; cv=none; d=zohomail.com; s=zohoarc; b=jFkbqZMCULz7zDQyI2e8P63kBJ0ubm9HeTdo3MM++OYCWc0Thktr7NBTsSuVzMSNbhFsI2FiCjdtE7pKiaF45c+mmNWxdkxj7LubR1PbS7ty8W11sgCPqay1KHnyM5AI3ZAYTTzKExotcOLJR5irjykD4DpHtHVF6vSivInnk+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615833227; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fWWeJn6aLiPnfFIqTJdojW7MYsA8Ah6EYQcBQWFcLVQ=; b=QcXhdCilMb049gfPFpNlJNGDPkAZ/sesM2NhdaA7fmuyTUoGFPkq0oUBXY8lyCpi+qHTtAJzL0blbAUR85h4whIhtBo09zohJOhYGp58s4X8h5Diat1C9pdXIoDt8cNJfbcaRNVYdH9r92evvB8OdsklF6NIZtUR3kJwh1/9Gl8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615833227518823.8801774861242; Mon, 15 Mar 2021 11:33:47 -0700 (PDT) Received: from localhost ([::1]:39590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLs2E-0003zB-Cp for importer@patchew.org; Mon, 15 Mar 2021 14:33:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLrZI-0002d2-3g; Mon, 15 Mar 2021 14:03:52 -0400 Received: from mail-pl1-f180.google.com ([209.85.214.180]:45299) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLrZG-0000rY-0S; Mon, 15 Mar 2021 14:03:51 -0400 Received: by mail-pl1-f180.google.com with SMTP id u18so15675693plc.12; Mon, 15 Mar 2021 11:03:49 -0700 (PDT) Received: from localhost.localdomain ([73.93.153.95]) by smtp.gmail.com with ESMTPSA id y194sm14267842pfb.21.2021.03.15.11.03.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Mar 2021 11:03:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fWWeJn6aLiPnfFIqTJdojW7MYsA8Ah6EYQcBQWFcLVQ=; b=hiy41nsQVJZXkF9JB0y7RfL02FSsM/stkuICt8c6kiMQwGlSUBSUmxFOEFFBcnnANT gv/27SkAjOgupckyovj8xSh4gswDuAZm1D9i6GrIIByfmJmn+zJya6QztQcbnSmz6+ON KzhwHeqg1MJx6YMi2Ve8dzB11Qubyz9dzKDpIOmCp9o6jdl0iIuVkRBV/a7FHU7H8eiC oOuvSMD/pfxHLwKM5QDRwu1/6nOB81+0EcTyv5/LOK7sEit6HdSo0VK1asDAV9zG1Qmy Jghszbz6muGxMWe84Z5mpy7h1VOBU310g6xEFnKPwbUXRYTsKyhTMOQ9uDVwuoNHpwlK ig1A== X-Gm-Message-State: AOAM533OOIs+HqrNukGzkyafXhudsuqjHFwrRZZ5jYHID1aQxF8bxfvt 9ltyK1DvQCPGpfeQd71b9FBW2dfkVcY= X-Google-Smtp-Source: ABdhPJwjuNrcZLthjcclIG3nWifYSlAYUhuyCteglbWW6e6l60WWBqXNnQhULkeMlTYBy31/x0uzkQ== X-Received: by 2002:a17:90a:4498:: with SMTP id t24mr324674pjg.78.1615831428023; Mon, 15 Mar 2021 11:03:48 -0700 (PDT) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v3 3/4] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Mon, 15 Mar 2021 11:03:40 -0700 Message-Id: <20210315180341.31638-4-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210315180341.31638-1-j@getutm.app> References: <20210315180341.31638-1-j@getutm.app> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=209.85.214.180; envelope-from=osy86github@gmail.com; helo=mail-pl1-f180.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Kevin Wolf , Peter Maydell , "open list:raw" , Max Reitz , Joelle van Dyne , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 d1ab3180ff..2a14b881d0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2326,8 +2326,11 @@ static int64_t raw_getlength(BlockDriverState *bs) again: #endif if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) { + size =3D 0; #ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) { + size =3D 0; + } #elif defined(DIOCGPART) { struct partinfo pi; @@ -2336,9 +2339,7 @@ again: else size =3D 0; } - if (size =3D=3D 0) -#endif -#if defined(__APPLE__) && defined(__MACH__) +#elif defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE) { uint64_t sectors =3D 0; uint32_t sector_size =3D 0; @@ -2346,19 +2347,15 @@ again: if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) =3D=3D 0 && ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) =3D=3D 0) { size =3D sectors * sector_size; - } else { - size =3D lseek(fd, 0LL, SEEK_END); - if (size < 0) { - return -errno; - } } } -#else - size =3D lseek(fd, 0LL, SEEK_END); +#endif + if (size =3D=3D 0) { + size =3D lseek(fd, 0LL, SEEK_END); + } if (size < 0) { return -errno; } -#endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) switch(s->type) { case FTYPE_CD: --=20 2.28.0