From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=adacore.com ARC-Seal: i=1; a=rsa-sha256; t=1756886337; cv=none; d=zohomail.com; s=zohoarc; b=iuitlws0VuSRX+CP7m5MI5r9f5C02nnPU4e62PQNFpnvQKrmxEvH3M2nuSi3buj7rkjplF1qtduTf4dVc3+OrfvwPl0xyOl0qEtf+Uy/Znbp4o8pveNsdkv0R9F6hX452fG4+F5c7K0DykxLNV+Q8tuYuTU1udBrojxHmXY4NcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756886337; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5Aa96lioobd3V/jZeaMPcPy1BST5QsMXEtIGLa9bUrQ=; b=YiCcwQi6ZN1RaY+gvILoahmCdyPIhonnYDuwOERqMJYjdqJUmv600+gCVZDowCGYW6eLhGvudqb7GpEAu6oOSyuw7qYr308x8qH0FM0N/CjAE9aww8WDww+vY5FrTZZ2IiZ0Zoyfjgef/ICiEK4aKcB/VJJuih6ou1NVmVFFb04= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756886337612599.4596977263946; Wed, 3 Sep 2025 00:58:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utiNX-0006oP-8J; Wed, 03 Sep 2025 03:58:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utiNL-0006he-JC for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:51 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1utiNH-0005Mu-VC for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:50 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-45b7d497ab9so56963755e9.0 for ; Wed, 03 Sep 2025 00:57:43 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:8880:8b9d:ac82:8ac6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e7d2393sm227923335e9.3.2025.09.03.00.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 00:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1756886262; x=1757491062; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5Aa96lioobd3V/jZeaMPcPy1BST5QsMXEtIGLa9bUrQ=; b=ShgARH4DwwB7L2NMQPXbz7RHcg2+vumOZMcbnkKrSVD+jwPNe55tMWK+KnFonZVRzQ SmAh4lSrJZKVCQru0DSlwcZHj87RRS+EKQ5RdbCQkEWwIUqrYHikD/cS0u+8Mp1tRSQk VbXWzgIMmZu5mCbJO+GWIvDE4bbOr6IBfUByXgVLQTnNrWNf9XRrnKDo0J/84dlGdKdn DRNn9lDB4MYXcA0GuWyymmdjNYEd0JbwHmXaQNDWJvqZ/NQoTZOcPSajIgcuYnpEBI6p Sb/nAx3pdq9qwE37CfQ9b0hRRB7Mfw4tkt68MKnbW7CFM3C2j98S4CbFWgV02SQcDgNC rpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756886262; x=1757491062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Aa96lioobd3V/jZeaMPcPy1BST5QsMXEtIGLa9bUrQ=; b=IVLN2exvs3DAhNIt8AOjUI5G2EkhgGbitZ8GwnCto5dhARPjEsl1m+MzBJSxqFQAY9 twhU402EDs8ElWf+BXtx3lX3+pF7m5Fp45RTDy8disnZtrXuKIR9uw47xUV3RPfS6PJ1 LZBLJZuMWihQIzVNpjbGWOmpXMpHzqPUVnay1T0OCcDhXddZZuv+uXK7skFkjW6mPJut Tdqz2RFDVvzFGh36b+PlEg2F/DZyX/tRQWxsk8LdAHjkCNsrh2CyIWqIDXlKOvARKjVE s2kJCrb1iFef4xTEZc/7sRbbCTNETFopg+D4MHXzO5RlSpOqpBM0a1jkXuBSz4stnm5A qiag== X-Gm-Message-State: AOJu0YwVmUU1NENmwraFOxv6s5Tbqa447dF75exN6/uKZwwdP9fU1yVk H/S+JlRmpxunT4EO7ogCZ8o7FcOz4ARRTbwITJBFNj2c0fhtHFTQTUYXKm9YsxUwBCzLgIx7kW4 xzhs= X-Gm-Gg: ASbGncsWdtB5v3zFCGADl2m6uNRlBoBqO6lUUGpwASDLzD8tgLe0DrTKLw30CSD8unR hMQS2lT4sNQcSXnPgXrPOMJYkSv3m+6iu1ClyIxRo6K0Y8gNp3lGuKqxXywoLs9Pv8gt07A2t5A OUVXdM/yCOaU3Lkx/mHaSn1/qwZ6G6IDHoiJ3oUPQERVBl0HaNLeCq50rXV/A0W1veyRRDl7OlD CffteMMb4gXcatWnwwfYNoRoA/mXQr+jjdrO8SvPHgf4bKv9Fbb5LNhRVDGPNwLrHqOPY4d40RD Kzuc+KshR/SueWROWe46W9A5NQJIc3N1Piqun6c6ZhGS3yIm7wDVwi18ZqCkM5ZspgfUQDiYgW9 QOJcG096PdLM9aJUYaFD/N27Za/TCJt24kOB6B1m4eA== X-Google-Smtp-Source: AGHT+IER6ZQF4y1a9JrKdpml7gocWmIaKwcbIdbCV8//1lbdpL5DwhY23XuCyroc/Cs2kk5agIkNew== X-Received: by 2002:a05:600c:8b23:b0:456:1dd2:4e3a with SMTP id 5b1f17b1804b1-45b855506e2mr110848455e9.3.1756886261734; Wed, 03 Sep 2025 00:57:41 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 1/5] vvfat: introduce no-mbr option Date: Wed, 3 Sep 2025 09:57:17 +0200 Message-Id: <20250903075721.77623-2-chigot@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903075721.77623-1-chigot@adacore.com> References: <20250903075721.77623-1-chigot@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::331; envelope-from=chigot@adacore.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @adacore.com) X-ZM-MESSAGEID: 1756886340432116600 This option when set prevents a master boot record (MBR) to be initialized. This is mandatory as some operating system don't recognized mounted disks if a MBR is present. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index 814796d918..0220dd828b 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1082,6 +1082,11 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Make the image writable", }, + { + .name =3D "no-mbr", + .type =3D QEMU_OPT_BOOL, + .help =3D "Do not add a Master Boot Record on this disk", + }, { /* end of list */ } }, }; @@ -1092,6 +1097,7 @@ static void vvfat_parse_filename(const char *filename= , QDict *options, int fat_type =3D 0; bool floppy =3D false; bool rw =3D false; + bool no_mbr =3D false; int i; =20 if (!strstart(filename, "fat:", NULL)) { @@ -1116,6 +1122,10 @@ static void vvfat_parse_filename(const char *filenam= e, QDict *options, rw =3D true; } =20 + if (strstr(filename, ":no-mbr:")) { + no_mbr =3D true; + } + /* Get the directory name without options */ i =3D strrchr(filename, ':') - filename; assert(i >=3D 3); @@ -1131,6 +1141,7 @@ static void vvfat_parse_filename(const char *filename= , QDict *options, qdict_put_int(options, "fat-type", fat_type); qdict_put_bool(options, "floppy", floppy); qdict_put_bool(options, "rw", rw); + qdict_put_bool(options, "no-mbr", no_mbr); } =20 static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, @@ -1196,7 +1207,10 @@ static int vvfat_open(BlockDriverState *bs, QDict *o= ptions, int flags, if (!s->fat_type) { s->fat_type =3D 16; } - s->offset_to_bootsector =3D 0x3f; + /* Reserver space for MBR */ + if (!qemu_opt_get_bool(opts, "no-mbr", false)) { + s->offset_to_bootsector =3D 0x3f; + } cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; heads =3D 16; secs =3D 63; --=20 2.34.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=adacore.com ARC-Seal: i=1; a=rsa-sha256; t=1756886393; cv=none; d=zohomail.com; s=zohoarc; b=cQOx7gILhCR1xgCBEsKwhMGwKZmNqiULvdJKAOsbg7DvYw/KFlJG4rPKb9dcF5OzQtbpvcSdw+8xYIMsrWtD4ZDsu7E9eBKCyX3nhKXl6eZ+wlmiUfVYoQZQIkd4vl63cgMdXjbw0gzvNT5STu+vmYIDZhnvqStb80d/ezEtPx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756886393; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=c7mag5avFW+do0t0a1WlckVOJ6fYCC2t3DfnVJEOqkM=; b=J5Oq6JwQcGKnws7HZvtNxg1MGQtOxGMhGDpc1EjNR41FBfLBen84F47p0oYxBLsfiOV7/KdOz5xWcOoYd+ToXUPLpN37Qa6JRJVXDG5sJcVWg/5DmR5+fPsGYasvVMb1ZlA4lhhy4diBCMf7sKkWawt5JFlBLQKea0Zi4K/rLew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17568863933541003.500496756221; Wed, 3 Sep 2025 00:59:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utiNb-0006sC-6G; Wed, 03 Sep 2025 03:58:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utiNI-0006gL-Jp for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:49 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1utiNG-0005N0-4O for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:48 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-45b8b8d45b3so28290915e9.1 for ; Wed, 03 Sep 2025 00:57:43 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:8880:8b9d:ac82:8ac6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e7d2393sm227923335e9.3.2025.09.03.00.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 00:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1756886262; x=1757491062; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c7mag5avFW+do0t0a1WlckVOJ6fYCC2t3DfnVJEOqkM=; b=VVHNG/O0zGlzDuRj+nnexINmujIJJaJFuHakLr4V5xPe5phBv8YHOMLBBJHpwZZvkf 30wlVyRdjzx2YPql3UvvZeSaIEJx7GSGXwVgqhtKMMYw9uAZtP94yeJtI+7+ndz0h0z0 dHAw2HCJpFNmztoM5XMwIhRPT++C4A69UM0/qIfoceOho4NRTvaSHiaOGjJSTnTU09/R r/B4hNcCNA/f7Qk9FfUGFqnQJvVjEu0DTfp627O6TMaLrB94pY3quFfE3mQLoBBg9MIr 3f+981Clk1FTyryX9Zi5NKcu3kKv7wigg5rg8uoxdCChVGtPmygYOv8f064GT+f5vEf5 TXrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756886262; x=1757491062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c7mag5avFW+do0t0a1WlckVOJ6fYCC2t3DfnVJEOqkM=; b=kiME7m4RuMfs46Qk+pDVBziCj/29oegzM5D8ipXBeYi4UfD/uT+ooJiHAA62+npBdL uEO+S/RR9KC+zbj0R0JcvFvgGXkTW9h2azt3xVX6BN91q4p1n7Oy/tm3Z05jjFhg5ps8 d3AfWtDuHv8LOsIrwljTdYCYD5QoaT/YtvBDSsJ642Cycy12LSap6CHW/gteT1CIb/UY /N8fh82Jbpy7q4QtyQQ+NBxwwm+oPaZFtKKqXHU98WzSUw9x3Z3crYkOYvpFJxfRLvCa CmWefymHmNTXVBqTqaBQJsPOmhc86pNeLXLdYy5SwFARi2NOl9V2Ql5P5lTUDFaCTEvt YYhQ== X-Gm-Message-State: AOJu0YzlMllXVvUpJfPP2fAdH0f3HDdW4CGoVbGQrZxUuPCrjmJg2bpR Vfo0z4GYKgHWuw6INtABPIeEGyVowHe87fdwka9TSG+XuxUwV5Nvi0zfOjpdzyAYaWZB58YSn+h n9EA= X-Gm-Gg: ASbGncvYN8SIByY88YHBtgPMzJqYbwKSpfuSbqlezQyeskC/zr1Oca+nm9HCeWy3oZt QIS6hEU+Q8OnurJCLVKp+QWih8lakPeGpbYNgblwMel/dbkbjFBjWiYK0M544C4TWKee4EBIv9J NmPaROLbSlOs62HCpZlkS1Q1FL4ZIUlpzqrN8w+pmLM28Ld6NPgPX52NXmLs1BiBwN3Nzkf03Ez BMZX938OCwSPby2FqApCaqfTjOUvIXcl5MCv3evJfPZh7m11u77fD5bGO6OikXuav2ytweqDmSa qbMk+ZbBDCtTyKz91lnX0cDEt3ciwGYac8lVINoo6IgfQYsvOV/IRDh4KsVq1xzFOyfIGRWPjqG 6oN3qs9SFljer2h01et5kprA0p3ooOVAo6mxNWC4NouS8QE7yEUOn X-Google-Smtp-Source: AGHT+IHymHFqVyEXL2NfEOtxTjsRdjNonDf9Ojrc+0nCM67ZpQJyVaxCKkBp6DBE6Ox0NAvr9Crg/w== X-Received: by 2002:a05:600c:4f8f:b0:456:f1e:205c with SMTP id 5b1f17b1804b1-45b85550704mr117013025e9.4.1756886262282; Wed, 03 Sep 2025 00:57:42 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 2/5] vvfat: move fat_type check prior to size setup Date: Wed, 3 Sep 2025 09:57:18 +0200 Message-Id: <20250903075721.77623-3-chigot@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903075721.77623-1-chigot@adacore.com> References: <20250903075721.77623-1-chigot@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::329; envelope-from=chigot@adacore.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @adacore.com) X-ZM-MESSAGEID: 1756886395577124100 This allows to handle the default FAT size in a single place and make the following part taking care only about size parameters. It will be later moved away in a specific function. Setting a floppy disk of 1MB is no longer possible as it was a side effect of passing "fat-type=3D12". To be precise there were three cases: - fat-type undefined (aka default): a fat12 2MB disk - fat-type=3D16: a fat16 2Mb disk - fat-type=3D12: a fat12 1Mb disk Now, that fat-type undefined means fat-type=3D2, it's no longer possible to make that size distinction. It will be added back a bit later, through the size parameter. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 0220dd828b..91e4ad3158 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1190,45 +1190,51 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, memcpy(s->volume_label, "QEMU VVFAT", 10); } =20 - if (floppy) { - /* 1.44MB or 2.88MB floppy. 2.88MB can be FAT12 (default) or FAT1= 6. */ - if (!s->fat_type) { + /* Verify FAT type */ + switch (s->fat_type) { + case 32: + warn_report("FAT32 has not been tested. You are welcome to do so!"= ); + break; + case 16: + case 12: + break; + case 0: + /* Set a default type */ + if (floppy) { s->fat_type =3D 12; + } else { + s->fat_type =3D 16; + } + break; + default: + error_setg(errp, "Valid FAT types are only 12, 16 and 32"); + ret =3D -EINVAL; + goto fail; + } + + + if (floppy) { + /* 2.88MB floppy */ + if (s->fat_type =3D=3D 12) { secs =3D 36; s->sectors_per_cluster =3D 2; } else { - secs =3D s->fat_type =3D=3D 12 ? 18 : 36; + secs =3D 36; s->sectors_per_cluster =3D 1; } cyls =3D 80; heads =3D 2; } else { - /* 32MB or 504MB disk*/ - if (!s->fat_type) { - s->fat_type =3D 16; - } /* Reserver space for MBR */ if (!qemu_opt_get_bool(opts, "no-mbr", false)) { s->offset_to_bootsector =3D 0x3f; } + /* 32MB or 504MB disk*/ cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; heads =3D 16; secs =3D 63; } =20 - switch (s->fat_type) { - case 32: - warn_report("FAT32 has not been tested. You are welcome to do so!"= ); - break; - case 16: - case 12: - break; - default: - error_setg(errp, "Valid FAT types are only 12, 16 and 32"); - ret =3D -EINVAL; - goto fail; - } - =20 s->bs =3D bs; =20 --=20 2.34.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=adacore.com ARC-Seal: i=1; a=rsa-sha256; t=1756886354; cv=none; d=zohomail.com; s=zohoarc; b=AR4JE6Svqd8G6AC58XADGpG9TEpCdD+F/K1upDRZN/3MPh9kEAghFNt6u7Bl2vOMU4V+l7Mxa1cB/bE3oW8jsZztzMVjf3U+QzFDahDcryr0zQHoI6MJ/5Oa8HIip7KpyLb4On9l4+deRrxkjZFmWy+PvYfnhNn4K0QcRGEgXKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756886354; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LKDt9NbbQt4YL2i2ghhzO4DBHVA7LMjZYIaUTZlT55U=; b=KzV3pxDyFViB0H7ii2z+oJ6TljMmnoQFxQonGad2WNsukQmF8V7ofPcTvcg0rAz9iXT6N2SFd6K3M++1lDM9W6QmqdzW+3ZpGFuou2wjxHmXOXHiCrBsJnwJDHX/SrE5+huRFSCNuEq4adBde06UpIfQT6G9L2QYWohmOZW5Fuc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756886354714508.24583498098775; Wed, 3 Sep 2025 00:59:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utiNc-0006sm-3C; Wed, 03 Sep 2025 03:58:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utiNK-0006h8-43 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:51 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1utiNG-0005N7-E9 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:49 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3d1bf79d7acso2298680f8f.0 for ; Wed, 03 Sep 2025 00:57:44 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:8880:8b9d:ac82:8ac6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e7d2393sm227923335e9.3.2025.09.03.00.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 00:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1756886263; x=1757491063; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LKDt9NbbQt4YL2i2ghhzO4DBHVA7LMjZYIaUTZlT55U=; b=MoiIKnXoETPkKwjp/Z+DRaPf2FuteV+FrB682JpLlXcx3kwCtYmymkMG6+l/r/2b1K i9ocEfiBceNgieob4LcfeXLZQAg6QB9F6ZkC3ZcjHS1o9vfLoIrf8HBHeH0/iSbxy8Mj H6mT9audAfZfadm9q03vNDZ/WHaktrJduxQIUed+F9Xnc0H7oSrv3NT5fzp3QDY1n/lu K7VvGXiyzPQ+f/i3kv/jW90QNb87LZ41RtmuVBd8qzF0YdYuXPkJh52ZedK5k69wLZeu TFWc/+ZGmfX8RkLNJo/ZtvQL6y1GhzP686iUYmMgGz9v+/2Pi/K+vGMAc3fqUc05Tzfe UaAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756886263; x=1757491063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LKDt9NbbQt4YL2i2ghhzO4DBHVA7LMjZYIaUTZlT55U=; b=iZESc0mzNA0vElIzezmZhdQfUYK6g/VgrVt1fc3FEAITq2RlRmwzGJen90uZyB8Q0k J12yrPrN1R9WJXu/uGdhZaN1sBx+4Ueh87sbOEUh3CriVHiPT+5QvrMXGawAHwn2pPoa XIQL75Fcarp+HefIiq6JdAT5LBEXtfkUueQHU5lG7gaFV0c/fmhQ4OQHSg+Xh1yp/vi2 GsXx60Rf0XEF2z1mzcHNJ8zfALR+iRoaKq96ATfL9PjiJKYTOgN5PKABtPyVP27EaDUb DaDpB27tKFYx4QTB8C6wwB2CPMT+E1Uq0+UUw32kffU2fr4RNzKj3xggmHbgxh4PecGY bdOQ== X-Gm-Message-State: AOJu0YysMmn2w2BQminb5e88o2IpH9NTrbU6vg7KJbKz1GfvJIfreXkP 3bAydPUJK1k9AS0MxAoOErIZf7Nk4E3S6aMGg6IXbJCjJzNTm5lmhYKAapYSGxbcM1kPFBi6oA4 Rp1U= X-Gm-Gg: ASbGncv5FORqTapSTVGycVB90wYWCqwXWWQjETaOl+eQADQ7vUlm6CjAmKL5NKXmUg8 wujbZcTEBnLMV5lumuZlSkZ8CErY3PcG71OSoRVgbbxBr6cMd2VaaMqcb/g9s/aoH3VOWh/lggq tIKAV1tORs+LVSuB0iCZAkvyRVtIEvE8HYK/qMQQbSwIRBaiqxx0zVwsF6XOXMGjvHQ0HByRjci CTx5y9tugwc+SMblRGut2H8aVfn28Dl3aT7N2jR9PVIZf7ZCmZZ5AuBW8BHeZL1umGiM8nxeov/ MuhqZ1m+1oYV1A16mvSZuQlfmjL9+xqAQLhjZeJ5SOxof5+DTwKgm1Dn8VAvMK/mad5ijHEYm6c JgW3GlumN5fYDIfnM660O/3oZoX26KuYc9e2adaqVZQ== X-Google-Smtp-Source: AGHT+IEhtyqWymREAN5C48vsH4ddzrdoo+5K6a4GShj3M7XfKLyMmdxw1qJc1G6ITMRodDyYlYjL1A== X-Received: by 2002:a05:6000:420e:b0:3c9:f8a:f257 with SMTP id ffacd0b85a97d-3d1e05b5facmr11247699f8f.50.1756886262858; Wed, 03 Sep 2025 00:57:42 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 3/5] vvfat: add a define for SECTOR_SIZE Date: Wed, 3 Sep 2025 09:57:19 +0200 Message-Id: <20250903075721.77623-4-chigot@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903075721.77623-1-chigot@adacore.com> References: <20250903075721.77623-1-chigot@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::431; envelope-from=chigot@adacore.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @adacore.com) X-ZM-MESSAGEID: 1756886357300124100 This makes those 0x200 far clearer. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 60 ++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 91e4ad3158..6b6d158a18 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -75,6 +75,8 @@ static void checkpoint(void); */ #define BOOTSECTOR_OEM_NAME "MSWIN4.1" =20 +#define SECTOR_SIZE 0x200 + #define DIR_DELETED 0xe5 #define DIR_KANJI DIR_DELETED #define DIR_KANJI_FAKE 0x05 @@ -300,7 +302,7 @@ static void print_mapping(const struct mapping_t* mappi= ng); typedef struct BDRVVVFATState { CoMutex lock; BlockDriverState* bs; /* pointer to parent */ - unsigned char first_sectors[0x40*0x200]; + unsigned char first_sectors[0x40 * SECTOR_SIZE]; =20 int fat_type; /* 16 or 32 */ array_t fat,directory,mapping; @@ -689,11 +691,11 @@ static inline void init_fat(BDRVVVFATState* s) if (s->fat_type =3D=3D 12) { array_init(&(s->fat),1); array_ensure_allocated(&(s->fat), - s->sectors_per_fat * 0x200 * 3 / 2 - 1); + s->sectors_per_fat * SECTOR_SIZE * 3 / 2 - 1); } else { array_init(&(s->fat),(s->fat_type=3D=3D32?4:2)); array_ensure_allocated(&(s->fat), - s->sectors_per_fat * 0x200 / s->fat.item_size - 1); + s->sectors_per_fat * SECTOR_SIZE / s->fat.item_size - 1); } memset(s->fat.pointer,0,s->fat.size); =20 @@ -901,19 +903,19 @@ static int init_directories(BDRVVVFATState* s, unsigned int i; unsigned int cluster; =20 - memset(&(s->first_sectors[0]),0,0x40*0x200); + memset(&(s->first_sectors[0]), 0 , 0x40 * SECTOR_SIZE); =20 - s->cluster_size=3Ds->sectors_per_cluster*0x200; + s->cluster_size =3D s->sectors_per_cluster * SECTOR_SIZE; s->cluster_buffer=3Dg_malloc(s->cluster_size); =20 /* - * The formula: sc =3D spf+1+spf*spc*(512*8/fat_type), + * The formula: sc =3D spf+1+spf*spc*(SECTOR_SIZE*8/fat_type), * where sc is sector_count, * spf is sectors_per_fat, * spc is sectors_per_clusters, and * fat_type =3D 12, 16 or 32. */ - i =3D 1+s->sectors_per_cluster*0x200*8/s->fat_type; + i =3D 1 + s->sectors_per_cluster * SECTOR_SIZE * 8 / s->fat_type; s->sectors_per_fat=3D(s->sector_count+i)/i; /* round up */ =20 s->offset_to_fat =3D s->offset_to_bootsector + 1; @@ -1011,12 +1013,12 @@ static int init_directories(BDRVVVFATState* s, s->current_mapping =3D NULL; =20 bootsector =3D (bootsector_t *)(s->first_sectors - + s->offset_to_bootsector * 0x200); + + s->offset_to_bootsector * SECTOR_SIZE); bootsector->jump[0]=3D0xeb; bootsector->jump[1]=3D0x3e; bootsector->jump[2]=3D0x90; memcpy(bootsector->name, BOOTSECTOR_OEM_NAME, 8); - bootsector->sector_size=3Dcpu_to_le16(0x200); + bootsector->sector_size =3D cpu_to_le16(SECTOR_SIZE); bootsector->sectors_per_cluster=3Ds->sectors_per_cluster; bootsector->reserved_sectors=3Dcpu_to_le16(1); bootsector->number_of_fats=3D0x2; /* number of FATs */ @@ -1513,7 +1515,7 @@ vvfat_read(BlockDriverState *bs, int64_t sector_num, = uint8_t *buf, int nb_sector " allocated\n", sector_num, n >> BDRV_SECTOR_BITS)); if (bdrv_co_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, = n, - buf + i * 0x200, 0) < 0) { + buf + i * SECTOR_SIZE, 0) < 0) { return -1; } i +=3D (n >> BDRV_SECTOR_BITS) - 1; @@ -1525,19 +1527,19 @@ vvfat_read(BlockDriverState *bs, int64_t sector_num= , uint8_t *buf, int nb_sector } if (sector_num < s->offset_to_root_dir) { if (sector_num < s->offset_to_fat) { - memcpy(buf + i * 0x200, - &(s->first_sectors[sector_num * 0x200]), - 0x200); + memcpy(buf + i * SECTOR_SIZE, + &(s->first_sectors[sector_num * SECTOR_SIZE]), + SECTOR_SIZE); } else if (sector_num < s->offset_to_fat + s->sectors_per_fat)= { - memcpy(buf + i * 0x200, + memcpy(buf + i * SECTOR_SIZE, &(s->fat.pointer[(sector_num - - s->offset_to_fat) * 0x200]), - 0x200); + - s->offset_to_fat) * SECTOR_SIZE]), + SECTOR_SIZE); } else if (sector_num < s->offset_to_root_dir) { - memcpy(buf + i * 0x200, + memcpy(buf + i * SECTOR_SIZE, &(s->fat.pointer[(sector_num - s->offset_to_fat - - s->sectors_per_fat) * 0x200]), - 0x200); + - s->sectors_per_fat) * SECTOR_SIZE= ]), + SECTOR_SIZE); } } else { uint32_t sector =3D sector_num - s->offset_to_root_dir, @@ -1545,10 +1547,12 @@ vvfat_read(BlockDriverState *bs, int64_t sector_num= , uint8_t *buf, int nb_sector cluster_num=3Dsector/s->sectors_per_cluster; if(cluster_num > s->cluster_count || read_cluster(s, cluster_n= um) !=3D 0) { /* LATER TODO: strict: return -1; */ - memset(buf+i*0x200,0,0x200); + memset(buf + i * SECTOR_SIZE, 0, SECTOR_SIZE); continue; } - memcpy(buf+i*0x200,s->cluster+sector_offset_in_cluster*0x200,0= x200); + memcpy(buf + i * SECTOR_SIZE, + s->cluster + sector_offset_in_cluster * SECTOR_SIZE, + SECTOR_SIZE); } } return 0; @@ -2176,7 +2180,7 @@ DLOG(checkpoint()); * - if all is fine, return number of used clusters */ if (s->fat2 =3D=3D NULL) { - int size =3D 0x200 * s->sectors_per_fat; + int size =3D SECTOR_SIZE * s->sectors_per_fat; s->fat2 =3D g_malloc(size); memcpy(s->fat2, s->fat.pointer, size); } @@ -2573,7 +2577,8 @@ commit_one_file(BDRVVVFATState* s, int dir_index, uin= t32_t offset) (size > offset && c >=3D2 && !fat_eof(s, c))); =20 ret =3D vvfat_read(s->bs, cluster2sector(s, c), - (uint8_t*)cluster, DIV_ROUND_UP(rest_size, 0x200)); + (uint8_t *)cluster, + DIV_ROUND_UP(rest_size, SECTOR_SIZE)); =20 if (ret < 0) { qemu_close(fd); @@ -2952,7 +2957,7 @@ static int coroutine_fn GRAPH_RDLOCK do_commit(BDRVVV= FATState* s) } =20 /* copy FAT (with bdrv_pread) */ - memcpy(s->fat.pointer, s->fat2, 0x200 * s->sectors_per_fat); + memcpy(s->fat.pointer, s->fat2, SECTOR_SIZE * s->sectors_per_fat); =20 /* recurse direntries from root (using bs->bdrv_pread) */ ret =3D commit_direntries(s, 0, -1); @@ -3016,14 +3021,14 @@ DLOG(checkpoint()); * used to mark volume dirtiness */ unsigned char *bootsector =3D s->first_sectors - + s->offset_to_bootsector * 0x200; + + s->offset_to_bootsector * SECTOR_SIZ= E; /* * LATER TODO: if FAT32, this is wrong (see init_directories(), * which always creates a FAT16 bootsector) */ const int reserved1_offset =3D offsetof(bootsector_t, u.fat16.rese= rved1); =20 - for (i =3D 0; i < 0x200; i++) { + for (i =3D 0; i < SECTOR_SIZE; i++) { if (i !=3D reserved1_offset && bootsector[i] !=3D buf[i]) { fprintf(stderr, "Tried to write to protected bootsector\n"= ); return -1; @@ -3078,7 +3083,8 @@ DLOG(checkpoint()); end =3D sector_num + nb_sectors; dir_index =3D mapping->dir_index + 0x10 * (begin - mapping->begin * s->sectors_per_cluste= r); - direntries =3D (direntry_t*)(buf + 0x200 * (begin - sector= _num)); + direntries =3D + (direntry_t *)(buf + SECTOR_SIZE * (begin - sector_num= )); =20 for (k =3D 0; k < (end - begin) * 0x10; k++) { /* no access to the direntry of a read-only file */ --=20 2.34.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=adacore.com ARC-Seal: i=1; a=rsa-sha256; t=1756886396; cv=none; d=zohomail.com; s=zohoarc; b=ddqqYsZbn+ADURbApayCSsYdTa9s14JMJir4Cb33AglZQvauDaXpeFNJ15mXdbFubguM2f+5tkE66Uduv6jMjDk06hzcuj4taBN3MCiBHCMJ2rBaOxiCbyPIxE7qnmx7AKa8H3/51of6RV5+6g4cVeOEEa8rmTH8CrKcFosKJ70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756886396; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2MvWn5d6XqQ+RCyxskwcO5xPTfuSIuv1nwogU1KNBQ8=; b=n43okRd0y4zYEgAeWjqlTCo817mqJJLEvDdOwjxXynVFY1WVXjRSqXaZy15mHCkFtY3rxdKNERecYjzRKBxSHe/BT6JcwF+JzpAUnppKrPFZrmcdPFUed6PMxej3qMt7pxjUg0qmt04gcDM7t9FkzNt9rzcfEY8K+95QBTEoq+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756886396659723.7121303713113; Wed, 3 Sep 2025 00:59:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utiNd-0006uK-9P; Wed, 03 Sep 2025 03:58:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utiNI-0006gU-Rm for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:49 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1utiNG-0005NE-4V for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:48 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-45cb6d8f42cso780205e9.1 for ; Wed, 03 Sep 2025 00:57:45 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:8880:8b9d:ac82:8ac6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e7d2393sm227923335e9.3.2025.09.03.00.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 00:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1756886263; x=1757491063; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2MvWn5d6XqQ+RCyxskwcO5xPTfuSIuv1nwogU1KNBQ8=; b=GtGpTbhBma1nDwEoo2k83CnUOld89RjZv8DLxRLCB6EvXmlnYN0ZY8nmePvSJgAszN JDZTDEysrqaP0n8RJumb+3Ppr1nT1QNOjh8DeHEdrWLG4NSwrhCjQmpZ+oFdTXVYCfRd x3WGVDgZSM7up2BNRSXVd5hSB42VJs7XdQdoeydUgXVr3oONVYKoOLFgBR9W3lS94G/p 7TvxesNKf/L5GVWbLoO+G2K+ZwXY+5BfRddBx4PT/DtdBpsQ6pS3GDg49AMMFOaIKDp1 lTLp0N1jndC3ngso1neI1qNCBdigw0oPLxXKfHixoDGdRwsv5LRt4U9mnLeu1AEpmOZd H3uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756886263; x=1757491063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2MvWn5d6XqQ+RCyxskwcO5xPTfuSIuv1nwogU1KNBQ8=; b=bHje9LB7Gy6Kpr/f2W3jZm20uu2LUQTLVINm3bD3MZLUD2wgwgGUykSFdjoJaqC1k5 HU1PKNy6XQzxXBCJ1SoRFnVMx1cVYJ48E12a1/a1YiyAJM0qSzFSEx/+z4H8MAsMc5SG IexxosaBcEYTZBvPHDzLxgW90KmjcTvaE+4ty7q5qva08LD+K0rewvhqqn6fKiG23V3p dqe6TAmjqzdpLq8Wx6cYCfTvsjx2cEGHZnyr0pwx9OSR/lLbjmGvpV2n+aQIKOVHlyr7 wpT8IVtFf3PhS4VE2S9gXz52GmFtwjNxWuqtspoMjeEne43N0eNvtLLomdlR230+Wmwi HI1A== X-Gm-Message-State: AOJu0YwEBDQJhYxRgtj0GpDfyHAMFYowUi0WpTuStWgaCRj5UuZmTLXR ypY4sZJw7AgFla9PkX3Z5jpOmhwnt9iES5+2+4kGTBFMrcEnlQP9S2PeQZ2QCl8dZCmKJwZZA1E bdRc= X-Gm-Gg: ASbGncvdMXPwDEdnl2QrgmBnly2n2q+MZsUlHUxlWjKda1RcjtfdWo3PSIuM/Fk3jFH l+d9F6QML2Otojp2uh5qpTvFfpM4EWE7sdNn8b4QUbqeAL5qLdxeZt4SFib0VJZ48UMqiXmPTbS huQVPsqD3ujvEQT5Gr7IcmdtC89tShPV6dQwQebr3NP+GFvNnuYkIc61baVd8dUasI4rWDM+Uo3 7PYk+4inT+J1z8KzOr3v0Ks8OBZbMbgwk4QSbl68LLlaZw6tHHSz6C3mICUZe383SSJ815KUp4p F/ZFw2wjUhvy2VIPOk+3FlmNzvV9sRc5AVVY6NTjZz7je40yZq8wpWrDReVEd613DFwgPJy6xea HvmmmooSnqi9r44viM2BcVbJRl+L/Gc6DL6dLTmBNtQ== X-Google-Smtp-Source: AGHT+IFBYg85jtegp+rgc85j74OZxoHz/h7YMsDcACMjB31tKBf9twDAaWdraEPqVlP+FccJHzysPg== X-Received: by 2002:a05:600c:5486:b0:45b:8d2a:cd09 with SMTP id 5b1f17b1804b1-45b9bd607a7mr31567385e9.13.1756886263393; Wed, 03 Sep 2025 00:57:43 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 4/5] vvfat: move size parameters within driver structure Date: Wed, 3 Sep 2025 09:57:20 +0200 Message-Id: <20250903075721.77623-5-chigot@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903075721.77623-1-chigot@adacore.com> References: <20250903075721.77623-1-chigot@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32b; envelope-from=chigot@adacore.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @adacore.com) X-ZM-MESSAGEID: 1756886399024116600 At the same time, rename them to match bootsector fields. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 6b6d158a18..6526c585a2 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -310,7 +310,10 @@ typedef struct BDRVVVFATState { =20 uint32_t offset_to_bootsector; /* 0 for floppy, 0x3f for disk */ =20 + unsigned int cylinders; unsigned int cluster_size; + unsigned int number_of_heads; + unsigned int sectors_per_track; unsigned int sectors_per_cluster; unsigned int sectors_per_fat; uint32_t last_cluster_of_root_directory; @@ -364,7 +367,7 @@ static int sector2CHS(mbr_chs_t *chs, int spos, int cyl= s, int heads, int secs) return 0; } =20 -static void init_mbr(BDRVVVFATState *s, int cyls, int heads, int secs) +static void init_mbr(BDRVVVFATState *s) { /* TODO: if the files mbr.img and bootsect.img exist, use them */ mbr_t* real_mbr=3D(mbr_t*)s->first_sectors; @@ -380,9 +383,9 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int h= eads, int secs) =20 /* LBA is used when partition is outside the CHS geometry */ lba =3D sector2CHS(&partition->start_CHS, s->offset_to_bootsector, - cyls, heads, secs); + s->cylinders, s->number_of_heads, s->sectors_per_tra= ck); lba |=3D sector2CHS(&partition->end_CHS, s->bs->total_sectors - 1, - cyls, heads, secs); + s->cylinders, s->number_of_heads, s->sectors_per_tra= ck); =20 /*LBA partitions are identified only by start/length_sector_long not b= y CHS*/ partition->start_sector_long =3D cpu_to_le32(s->offset_to_bootsector); @@ -894,8 +897,7 @@ static inline off_t cluster2sector(BDRVVVFATState* s, u= int32_t cluster_num) return s->offset_to_root_dir + s->sectors_per_cluster * cluster_num; } =20 -static int init_directories(BDRVVVFATState* s, - const char *dirname, int heads, int secs, +static int init_directories(BDRVVVFATState *s, const char *dirname, Error **errp) { bootsector_t* bootsector; @@ -1028,8 +1030,8 @@ static int init_directories(BDRVVVFATState* s, bootsector->media_type =3D (s->offset_to_bootsector > 0 ? 0xf8 : 0xf0); s->fat.pointer[0] =3D bootsector->media_type; bootsector->sectors_per_fat=3Dcpu_to_le16(s->sectors_per_fat); - bootsector->sectors_per_track =3D cpu_to_le16(secs); - bootsector->number_of_heads =3D cpu_to_le16(heads); + bootsector->sectors_per_track =3D cpu_to_le16(s->sectors_per_track); + bootsector->number_of_heads =3D cpu_to_le16(s->number_of_heads); bootsector->hidden_sectors =3D cpu_to_le32(s->offset_to_bootsector); bootsector->total_sectors=3Dcpu_to_le32(s->sector_count>0xffff?s->sect= or_count:0); =20 @@ -1150,7 +1152,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, Error **errp) { BDRVVVFATState *s =3D bs->opaque; - int cyls, heads, secs; bool floppy; const char *dirname, *label; QemuOpts *opts; @@ -1218,23 +1219,23 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, if (floppy) { /* 2.88MB floppy */ if (s->fat_type =3D=3D 12) { - secs =3D 36; + s->sectors_per_track =3D 36; s->sectors_per_cluster =3D 2; } else { - secs =3D 36; + s->sectors_per_track =3D 36; s->sectors_per_cluster =3D 1; } - cyls =3D 80; - heads =3D 2; + s->cylinder =3D 80; + s->number_of_heads =3D 2; } else { /* Reserver space for MBR */ if (!qemu_opt_get_bool(opts, "no-mbr", false)) { s->offset_to_bootsector =3D 0x3f; } /* 32MB or 504MB disk*/ - cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; - heads =3D 16; - secs =3D 63; + s->cylinders =3D s->fat_type =3D=3D 12 ? 64 : 1024; + s->number_of_heads =3D 16; + s->sectors_per_track =3D 63; } =20 =20 @@ -1251,10 +1252,13 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, s->downcase_short_names =3D 1; =20 DLOG(fprintf(stderr, "vvfat %s chs %d,%d,%d\n", - dirname, cyls, heads, secs)); + dirname, s->cylinders, s->number_of_heads, + s->sectors_per_track)); =20 - s->sector_count =3D cyls * heads * secs - s->offset_to_bootsector; - bs->total_sectors =3D cyls * heads * secs; + s->sector_count =3D s->cylinders * s->number_of_heads * + s->sectors_per_track - s->offset_to_bootsector; + bs->total_sectors =3D s->cylinders * s->number_of_heads * + s->sectors_per_track; =20 if (qemu_opt_get_bool(opts, "rw", false)) { if (!bdrv_is_read_only(bs)) { @@ -1275,7 +1279,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, } } =20 - if (init_directories(s, dirname, heads, secs, errp)) { + if (init_directories(s, dirname, errp)) { ret =3D -EIO; goto fail; } @@ -1296,7 +1300,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, } =20 if (s->offset_to_bootsector > 0) { - init_mbr(s, cyls, heads, secs); + init_mbr(s); } =20 qemu_co_mutex_init(&s->lock); --=20 2.34.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=adacore.com ARC-Seal: i=1; a=rsa-sha256; t=1756886397; cv=none; d=zohomail.com; s=zohoarc; b=b8dp1/TFIYZjWU+0ljJarpTS3k4/pva+ez5h8OWRw/2iqLkQ2QfxtoDbU/yjeBsXNKxuzvJ7iWGduH2lCewF+LgQT9LMmgze6EefVWUaaxqOC8TM2sk90/2ULM//30N8EQhggl/+YJpIXk+Pzgk1Nwn0WvntKsPlk6Y77BfE4+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756886397; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0exDSeWzfnLgVKcbfnAlGaanon91bsraDsnRd+gW7CM=; b=LIFhoS/tTUf4j6ZjaP1p/n0T2u5/kRtpBjENcHF40bYn4IqyVRYAC5Hde49pFo3+rZG5qfmURMNJxwntew0aLO0y3fDPadDRWAqjuVyzffxxUD34hjS1vQBkM+2yBbiid0bE4qpIJC3vL9UHxtkPbzOY8DQKd+9JA0ciRgCfgIo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756886397700903.1427614495132; Wed, 3 Sep 2025 00:59:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utiNa-0006rd-Oe; Wed, 03 Sep 2025 03:58:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utiNL-0006hg-JX for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:52 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1utiNG-0005NT-F1 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 03:57:50 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-45cb5492350so3348185e9.1 for ; Wed, 03 Sep 2025 00:57:45 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:8880:8b9d:ac82:8ac6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e7d2393sm227923335e9.3.2025.09.03.00.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 00:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1756886264; x=1757491064; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0exDSeWzfnLgVKcbfnAlGaanon91bsraDsnRd+gW7CM=; b=BnCiOrN4j5HIvJ9W1uEFzcQ6MVFDbwfEFWUhYB7t3X7HK2fZzPfDdE2Eh/N/BYxkII ZcIQ4vJbNeq6DVLdTbksxCiPUIJy3/SzUg73ZwUS/U3zs6dyVfQ6ol21CFZQBkiUFPUa USq2L/SMkc5Cg6N84IsI2zQDUNZVydU0K8vuFL2LRTs/buijQlNPtJPYLSGFMhYiR3K1 lzV9wfdt69+Cy1OzSU7RH6qU5YLZ3pvWTYcUjcIlsYxvu4b95qMF+YNPdr4CLoHnLyyF wtqZ2DWTp+UfV6uUkrmOHjRvgPlAeNaas0rZJigKNidgnBsd7a4tSYVGT9hPdysLGOcA FERQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756886264; x=1757491064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0exDSeWzfnLgVKcbfnAlGaanon91bsraDsnRd+gW7CM=; b=rzq1JHD6wAuslVg2Qv6WLeGhQvjVLNxAIpNTQDDwTSzNWzjii56KaI1SPDCGBLd2rv 0rWUVXVPpl3nRXr+kt18TNyLueWytbH3BSnsCcyQR38bfNtQB8TqzZLtft1isqIx6uwB W3Tt/R+cG7hDqberfEeg/h1wdgjEX7mEhOuXkLHdA5bkJVZWc6zRfooTOya2DfteRRlm AvIB5mTPXJO+nYFQOvESNNMl44+D6to7gKRWzU4TntxHFQo17mqKk9Ev7tjcIi4OA5tz 2nW3wnWLiTZ3Tfn9fSmXj4LDAGPnhBNwgUZPAZvLC1p6XXyaou/1dkFUpnmT7N07hJvt 66Ew== X-Gm-Message-State: AOJu0Yzr1Vhz95UTCq6GLTklPgDEWAf/lmRg1FAZjyeJl/kGg9ESEIcu G3BO8jGjaUqFt3gU1X2I3FyKrg0wXtKHKYdcm2xmAz71pJqWnAbjd40hQe7vIHKiDIkCgGyWnmU KvA4= X-Gm-Gg: ASbGncviKzI1VW7W8h7zkZU4bS2yFvRfMfCqjI7E26QVTR6DZuNFaCBawyUv15SR7O/ PZSvg/8/kjq4x5ChhVPjPyL1xTTzT/oro43PP+6dBdnaT2LO7aUK2vqR7n6mGSLGcE9T6U/7fTW 79M6PKg3oCoDwc2Q09QtgoOBy5IDM3YT6L0lftnT/o+7lKpWMfro3vIOU5SeY0Wv5UwBWp2K0+l 2vftGzIbwfEdKrS4OXft/HrAsrFrGU40PHo9ui+g5HjVny2DD10y/gwvGiepOyhpbvKGpu0lf8H q3U6h/7xTovLp/cUIQs2uU3zTbWTJ2B2O6WZPHgUAK/Sr4QS6UAUsvCigPcGdhCo+lFPNQM6LEM EiGQklXGScsTrzN2qy7STOQqsqCEzyoo= X-Google-Smtp-Source: AGHT+IErEv0qDU489Hu7ZOCZJv4PlePD6KaMfwHaHZwiYi0ntQhBm0aMK6ixqK4kWZKTh/CgWzSgkQ== X-Received: by 2002:a05:600c:4e88:b0:45c:b56c:4183 with SMTP id 5b1f17b1804b1-45cb56c43d1mr11171535e9.18.1756886263987; Wed, 03 Sep 2025 00:57:43 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 5/5] vvfat: add support for "size" options Date: Wed, 3 Sep 2025 09:57:21 +0200 Message-Id: <20250903075721.77623-6-chigot@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903075721.77623-1-chigot@adacore.com> References: <20250903075721.77623-1-chigot@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::32c; envelope-from=chigot@adacore.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @adacore.com) X-ZM-MESSAGEID: 1756886399635124100 This allows more flexibility to vvfat backend. The value for "Number of Heads" and "Sectors per track" are based on SD specifications Part 2. Some limitations remains, the size parameter is recognized only when "format=3Dvvfat" is passed. In particular, "format=3Draw,size=3Dxxx" is keeping the previously hardcoded value: 504MB for FAT16 and 32 MB for FAT12. FAT32 has not been adjusted and thus still default to 504MB. Moreover, for flopyy, size=3D1M is creating a disk 1.44 MB, and size=3D2M a disk of 2.88 MB. This avoids having to worry about float operations. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 165 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 141 insertions(+), 24 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 6526c585a2..4537c39d5c 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1091,6 +1091,11 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Do not add a Master Boot Record on this disk", }, + { + .name =3D BLOCK_OPT_SIZE, + .type =3D QEMU_OPT_SIZE, + .help =3D "Virtual disk size" + }, { /* end of list */ } }, }; @@ -1148,10 +1153,141 @@ static void vvfat_parse_filename(const char *filen= ame, QDict *options, qdict_put_bool(options, "no-mbr", no_mbr); } =20 +static void vvfat_get_size_parameters(uint64_t size, BDRVVVFATState *s, + bool floppy, Error **errp) +{ + if (floppy) { + /* + * Floppy emulation only supports 1.44 MB or 2.88 MB (default). + * In order to avoid floating operations ambiguity, 1 MB is + * recognized for 1.44 MB and 2 MB for 2.88 MB. + */ + if (!size) { + size =3D 2 * 1024 * 1024; + } else { + if (size =3D=3D 1024 * 1024 && s->fat_type =3D=3D 16) { + error_setg(errp, + "floppy FAT16 unsupported size; only support 2M= " + "(for an effective size of 2.88 MB)"); + } else if (size !=3D 2 * 1024 * 1024 && size !=3D 1024 * 1024)= { + error_setg(errp, + "floppy unsupported size; should be 1MB (for " + "an effective size of 1.44 MB) or 2.88M (for " + "2.88MB)"); + } + } + + if (s->fat_type =3D=3D 12) { + if (size =3D=3D 2 * 1024 * 1024) { + s->sectors_per_cluster =3D 2; + } else { + s->sectors_per_cluster =3D 1; + } + } else { + s->sectors_per_cluster =3D 1; + } + + s->sectors_per_track =3D 36; + s->cylinders =3D 80; + s->number_of_heads =3D 2; + } else { + /* LATER TODO: if FAT32, adjust */ + s->sectors_per_cluster =3D 0x10; + + switch (s->fat_type) { + case 12: + + /* Default is 32 MB */ + if (!size) { + size =3D 32 * 1024 * 1024; + } else if (size > 32 * 1024 * 1024) { + error_setg(errp, "FAT12 unsupported size; higher than 32Mb= "); + } + + s->cylinders =3D 64; + + /* + * Based on CHS Recommandation table: + * Card Capacity | Number of Headers | Sectors per track + * ~ 2 MB | 4 | 16 + * ~ 4 MB | 8 | 16 + * ~ 8 MB | 16 | 16 + * ~ 16 MB | 2 | 32 + * ~ 32 MB | 4 | 32 + * + * For 2 MB, SD is recommending heads =3D 2 and sectors =3D 16= , but + * this requires a different number of cylinders. Thus, it was + * adjusted to keep this number constant. + */ + if (size <=3D 8 * 1024 * 1024) { + s->sectors_per_track =3D 16; + } else { + s->sectors_per_track =3D 32; + } + + /* + * The formula between the size (in bytes) and the parameters = are: + * size =3D SECTOR_SIZE * sectors_per_track * number_of_heade= rs * + * cylinders + */ + s->number_of_heads =3D size / s->sectors_per_track / + SECTOR_SIZE / s->cylinders; + return; + + case 16: + /* Default is 504 MB */ + if (!size) { + size =3D 504 * 1024 * 1024; + } else if (size / 1024 > 4 * 1024 * 1024) { + error_setg(errp, "FAT16 unsupported size; higher than 4Gb"= ); + } + + s->cylinders =3D 1024; + + /* + * Based on CHS Recommandation table: + * Card Capacity | Number of Headers | Sectors per track + * ~64 MB | 4 | 32 + * ~128 MB | 8 | 32 + * ~256 MB | 16 | 32 + * ~504 MB | 16 | 63 + * ~1008 MB | 32 | 63 + * ~2016 MB | 64 | 63 + */ + if (size <=3D 256 * 1024 * 1024) { + s->sectors_per_track =3D 32; + } else { + s->sectors_per_track =3D 63; + } + + /* + * The formula between the size (in bytes) and the parameters = are: + * size =3D SECTOR_SIZE * sectors_per_track * number_of_heade= rs * + * cylinders + */ + s->number_of_heads =3D size / s->sectors_per_track / + SECTOR_SIZE / s->cylinders; + return; + + case 32: + /* TODO FAT32 adjust */ + if (size) { + warn_report("size parameters not supported with FAT32;" + "default to 504MB."); + } + s->cylinders =3D 1024; + s->number_of_heads =3D 16; + s->sectors_per_track =3D 63; + return; + } + } +} + static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVVVFATState *s =3D bs->opaque; + uint64_t size; bool floppy; const char *dirname, *label; QemuOpts *opts; @@ -1178,6 +1314,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, =20 s->fat_type =3D qemu_opt_get_number(opts, "fat-type", 0); floppy =3D qemu_opt_get_bool(opts, "floppy", false); + size =3D qemu_opt_get_size_del(opts, "size", 0); =20 memset(s->volume_label, ' ', sizeof(s->volume_label)); label =3D qemu_opt_get(opts, "label"); @@ -1215,35 +1352,15 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, goto fail; } =20 + vvfat_get_size_parameters(size, s, floppy, errp); =20 - if (floppy) { - /* 2.88MB floppy */ - if (s->fat_type =3D=3D 12) { - s->sectors_per_track =3D 36; - s->sectors_per_cluster =3D 2; - } else { - s->sectors_per_track =3D 36; - s->sectors_per_cluster =3D 1; - } - s->cylinder =3D 80; - s->number_of_heads =3D 2; - } else { - /* Reserver space for MBR */ - if (!qemu_opt_get_bool(opts, "no-mbr", false)) { - s->offset_to_bootsector =3D 0x3f; - } - /* 32MB or 504MB disk*/ - s->cylinders =3D s->fat_type =3D=3D 12 ? 64 : 1024; - s->number_of_heads =3D 16; - s->sectors_per_track =3D 63; + /* Reserver space for MBR */ + if (!floppy && !qemu_opt_get_bool(opts, "no-mbr", false)) { + s->offset_to_bootsector =3D 0x3f; } =20 - s->bs =3D bs; =20 - /* LATER TODO: if FAT32, adjust */ - s->sectors_per_cluster=3D0x10; - s->current_cluster=3D0xffffffff; =20 s->qcow =3D NULL; --=20 2.34.1