From nobody Sat Nov 29 10:17:25 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=1764253560; cv=none; d=zohomail.com; s=zohoarc; b=nlalbfJESOG0GH6ETePWA2I4/WrAMlC+/Yd2p6o1cpyJoJzyvHPeZxVJlrODN3OniigaR8NgHtRG9kl4QYI1UWAg8GbpZwPzCeOSjnFEI6f6W2KU/EFJrUKS5IRafsfTIfaKcnmyfkysd9ifYBS4GxViFykll3xGZzP8Iygym/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764253560; 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=ff3mnhdX3mWfpzK9gGdgsJWMgoiDPX053a6cG/860JI=; b=KZ0iQh8yyUz7fi/MaHH+OKdMdS7LpJMXGK048pJlTObGZdiT8Lop70uiRJv2efVAQh1at2IUxNY8Z/sVU+HdefwBh0LmPRyj1bvtZd/HfS2ybRYudqIlHsrivHUr3Ev9EFSeGbT8podcFmJ6J2OG97fJ7NPwCzkqQJ6y98Yf/JE= 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 1764253560336781.297380299863; Thu, 27 Nov 2025 06:26:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOcv7-0005f4-5y; Thu, 27 Nov 2025 09:24:29 -0500 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 1vOcv6-0005b3-7b for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:28 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOcv4-0006mE-5L for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:27 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-42b31c610fcso838578f8f.0 for ; Thu, 27 Nov 2025 06:24:25 -0800 (PST) Received: from chigot-Dell.. ([2a01:e0a:ca1:4970:e598:a2f0:7cc0:4392]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca1a2easm4148996f8f.23.2025.11.27.06.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 06:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1764253465; x=1764858265; 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=ff3mnhdX3mWfpzK9gGdgsJWMgoiDPX053a6cG/860JI=; b=Kcr4HwUAcWpSHj3nRhHL7FXspwIpkUXbAzzXcVtPFmvIRORje04J33233I0O97wh3y 5IdpwBfze8JE+cYNt1vQqgpLRgMHeKXiSNfzVWBdJXCFrnzNc19leFa+AHE6qmWH1qBV 7lKZGE+bsNZ7gJ1vx4nMOvjNSNRtKm4mOLZyuTTVyi3T+fSfsR7201Oz9FJVylkg+Fi1 pg5FWWMHIkJcLO1d8X7Dc6l4kCEjAJs3iDZhvuywpFEHsIHvu7DPVeeGIeOcZoWO3ig7 UGU2kwDlkOUHBJlsf60KCKbdftSypcJ3IV2pGxJVXhtl019HdLbrgrAGYkFreIm8EoSB PuAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764253465; x=1764858265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ff3mnhdX3mWfpzK9gGdgsJWMgoiDPX053a6cG/860JI=; b=YWJ8cIePA+gOE3yPf2Z5SIfK6V2nA8WoMhyGwBLnNy7EKuXnwXIyEPa8p16UdhFaeh 13q/D4wRGK77f/wlHpmZwTE2suBuOJWe9kgPDdZou4Nw3Vn2E7eo/6bQyo2iNPKkjVI7 C8vAOoLJR1v10G48w3GHYVTLKKQVC2BpzQghxAkTOK4RkbGsys5/v+H6JT89LhKFGcsc 69pWoMqQLBS3A94IXJeN/2DatjKdVa952Yj+IC/fTS10SAl9VAZvSiPJcImKYtdAyT6g ndzTBpXSOTvygfZ1slbReZR/55XOW4+1b2Yi4rJUtvLJN87k4jtEEbXQ7q7OJWv3+j3r 9SZg== X-Gm-Message-State: AOJu0YwmP6yMs2KJhshK1cXDJCkbiOtuAaOiEc9aJshmCLArCbB9VTl9 0PGvFf6+RE3kES0D8K+VQHLWFhXF1s3EqaQ3pOqUyQHq/Wg3GHqRM/+HCZTmfgarpQ== X-Gm-Gg: ASbGncvFpK+Wxz6FpPJRpHkxyZy1AZDHGfOfvNmR8J6geJgx+zmBY+cMuQaYsjmdzy6 UVaPdPJ2f+S9LSBpdDZBix/cnV1+euQvLUZ4uslCSKGgEUMdycdZgQgGkCCL3t8aOYt5L1x5lOr yIxUl7VkrvfxHfHSMLR+Z8i67frnrA3V4e4P9IIwH48yRMBUeo44uirXNRkwPHMsTDXM/PAzemn O+vJ6CWfu7XTo/UvcvTDmSbE0+eY9hPZWuAxTe3ANIl/MExNvFt0Rb1xFfoP4Y8mbO9jK1O+R34 z/B5/KGcQ+cy6FCPgz9A6AZgQl3L0bKSIZITLHWZEF4qbjAu+KNhkm/4x6Z6r06EZ7u/WDpwKn1 h+dnyix2fPHW+aOSbcLq+lYcySoYN267fH/aCg/lfIOVb4eLyZAlOeXBBihiFlX0XulZNvyb9Yk XcsE6yOzTHuTom X-Google-Smtp-Source: AGHT+IFgjLtvWu0ynA12FfSHsr4iw1tkXY9FEL8Hgm8LbN5uqywVTyMf/T59AeMhX+LKMACrLb8eGQ== X-Received: by 2002:a5d:4251:0:b0:42c:b8fd:21b3 with SMTP id ffacd0b85a97d-42e0f362440mr9069673f8f.57.1764253464626; Thu, 27 Nov 2025 06:24:24 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH v3 1/5] vvfat: introduce partitioned option Date: Thu, 27 Nov 2025 15:24:13 +0100 Message-ID: <20251127142417.710094-2-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251127142417.710094-1-chigot@adacore.com> References: <20251127142417.710094-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::42f; envelope-from=chigot@adacore.com; helo=mail-wr1-x42f.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: 1764253562861019200 This option tells whether the volume should be partitioned or not. Its default varies: true for hard disks and false for floppy. Its prime effect is to prevent a master boot record (MBR) to be initialized. This is useful as some operating system (QNX, Rtems) don't recognized FAT mounted disks (especially SD cards) if a MBR is present. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 19 ++++++++++++++++--- qapi/block-core.json | 10 +++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 814796d918..dd0b3689c1 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -306,7 +306,8 @@ typedef struct BDRVVVFATState { array_t fat,directory,mapping; char volume_label[11]; =20 - uint32_t offset_to_bootsector; /* 0 for floppy, 0x3f for disk */ + /* 0x3f for partitioned disk, 0x0 otherwise */ + uint32_t offset_to_bootsector; =20 unsigned int cluster_size; unsigned int sectors_per_cluster; @@ -1082,6 +1083,11 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Make the image writable", }, + { + .name =3D "partitioned", + .type =3D QEMU_OPT_BOOL, + .help =3D "Do not add a Master Boot Record on this disk", + }, { /* end of list */ } }, }; @@ -1138,7 +1144,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, { BDRVVVFATState *s =3D bs->opaque; int cyls, heads, secs; - bool floppy; + bool floppy, partitioned; const char *dirname, *label; QemuOpts *opts; int ret; @@ -1165,6 +1171,9 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, s->fat_type =3D qemu_opt_get_number(opts, "fat-type", 0); floppy =3D qemu_opt_get_bool(opts, "floppy", false); =20 + /* Hard disk are partitioned by default; floppy aren't. */ + partitioned =3D qemu_opt_get_bool(opts, "partitioned", floppy ? false = : true); + memset(s->volume_label, ' ', sizeof(s->volume_label)); label =3D qemu_opt_get(opts, "label"); if (label) { @@ -1196,7 +1205,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, if (!s->fat_type) { s->fat_type =3D 16; } - s->offset_to_bootsector =3D 0x3f; cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; heads =3D 16; secs =3D 63; @@ -1215,6 +1223,10 @@ static int vvfat_open(BlockDriverState *bs, QDict *o= ptions, int flags, goto fail; } =20 + /* Reserver space for MBR */ + if (partitioned) { + s->offset_to_bootsector =3D 0x3f; + } =20 s->bs =3D bs; =20 @@ -3246,6 +3258,7 @@ static const char *const vvfat_strong_runtime_opts[] = =3D { "floppy", "label", "rw", + "partitioned", =20 NULL }; diff --git a/qapi/block-core.json b/qapi/block-core.json index b82af74256..ca438fba51 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3464,8 +3464,8 @@ # # @fat-type: FAT type: 12, 16 or 32 # -# @floppy: whether to export a floppy image (true) or partitioned hard -# disk (false; default) +# @floppy: whether to export a floppy image (true) or hard disk +# (false; default) # # @label: set the volume label, limited to 11 bytes. FAT16 and FAT32 # traditionally have some restrictions on labels, which are @@ -3474,11 +3474,15 @@ # # @rw: whether to allow write operations (default: false) # +# @partitioned: whether the volume will be partitioned; +# (default: true for hard disk, false for floppy) +# (since 10.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsVVFAT', 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', - '*label': 'str', '*rw': 'bool' } } + '*label': 'str', '*rw': 'bool', '*partitioned': 'bool' } } =20 ## # @BlockdevOptionsGenericFormat: --=20 2.43.0 From nobody Sat Nov 29 10:17:25 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=1764253567; cv=none; d=zohomail.com; s=zohoarc; b=KCnmKF5RKaycE509RIOHSeo4nbN0t6a4f5x9T8RLwGMRZLEitSP5qCkhFSnivUcv9pszgPPOMrBpvE3wQ7XYPV77SxJBjXFf8DZG0Q22PD0R5C16IY+zuqA+58+8yBQyomRWJr5RO0vhS4De359PmJwHKNAODaiihtXJq7uIgzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764253567; 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=SNwzzkqCK4F2FAFtlDSFvQSqXPAaSXIjj5Frdipo5HY=; b=H0qZtA+HLvKxo5n90+QKQdoviEtOXsmwq+j3ApqX/4yJeb31tUCjxIBiWlnVOZvyJH6PPPPFzalyz8g8B6PYxAfQ35uc9+F0cmjo4V43/bNIBuQzR1Y5k20jofwvSy506B6eljFidU+dDf5r+uhY35QEIBKpbeoFSKYErnfrfE0= 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 1764253567568234.3309054273103; Thu, 27 Nov 2025 06:26:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOcv7-0005gh-KX; Thu, 27 Nov 2025 09:24:29 -0500 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 1vOcv6-0005cd-HX for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:28 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOcv4-0006mM-U7 for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:28 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-42b387483bbso808398f8f.1 for ; Thu, 27 Nov 2025 06:24:26 -0800 (PST) Received: from chigot-Dell.. ([2a01:e0a:ca1:4970:e598:a2f0:7cc0:4392]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca1a2easm4148996f8f.23.2025.11.27.06.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 06:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1764253465; x=1764858265; 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=SNwzzkqCK4F2FAFtlDSFvQSqXPAaSXIjj5Frdipo5HY=; b=fAl4l71QVstQFCFoXFqWuRPuU9aDkydqNYh7E5brKdDHrEp/frGEmTu3+sYOo7JGR6 rrbEMa0FtUSBYfwbfwN/+4b0yhor5NFUvVArGJGTB9+iOcEi0/kbflX0DbA7HmVDdo8d SXJgGfwaQE+EoPmqC1wJpnvx1fBlFibvrx5mjFn4mZgjBpC+KN+ySU85TLPVdIgRjkTq zcvnKJaNu8gH21wwJm92BtVaFl98bXv1GtBk4mSTZXYDNzYdc/97ymIEZlGcMRiCadtV Hu7warU/ntSSDqxysQ/L09D36uEwn/vij61a+u/FBTnWbWlmHGRnPzJCt5RpD8Cw0DJi 7H6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764253465; x=1764858265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SNwzzkqCK4F2FAFtlDSFvQSqXPAaSXIjj5Frdipo5HY=; b=IEVCzQLmgJ+W04YalEC71Ry5swLFYXnGkjP2zA3DUVoQsCIaSHLKMItXjGovxV6tXY nRZPJZ45/C16Onk6EDbgT5R2BjPfwGuAunDue/anjsn+o2kJBXgDi7opwaBw36uSJHRa ovNqzLhYdmAWJHBzsPcs5JEIQaTGHwHxCxNdjnfaoKkXjgCfGUYF6umV3CsHsNrWlT52 N7kGwlBFzuJRt7TsdBJx8gqZO1ooQAO9FN8P2t7zKo8Vmg1yryNf0L47d2Ke3Dfs8bXv bQlo5HErlrn3eTVHFqEY6df/nQoGxI4nb00b+HQGLN8SYM+5X6YXyRPRjF8nfS9jL3fn fd3A== X-Gm-Message-State: AOJu0Ywkl5f1r8GjqbMDT7Z+E6Z8akaW7j7wPgwvF95rCNwuOpdVJxnZ rTmb3BO9ayDTvJrU9lk8uERlv7eIoO7nCkZKYTLuFTT7wEuazdM+w1MfxR8uETb60g== X-Gm-Gg: ASbGncuFTC2MBFd+LnhiQjzY+h0RTN5i2wSIsD4QlXvUevr8FrN02RaKN8HKFWFX3E4 7CiQ+XnSRXkxpqufo2HVlscdY4WSOznfcmdl/6aIiSCGJTYSwDR7TL0K7EW17+vgx+MphoXXuu5 ePHAyZaUzuAEWuRNg4LZro2wwODd061kOza//8oAmlxBnnuFvnRkkj3lWKBcBG3PI3Y08qPNSJe ekTma7h3Lxlo6l2lCyH6ddfolDxva3X0tCcttwU81Xo+i71iddayhrmAnmCcYKGZRa/zFLiput2 JEzBMdNOMzzoiVKs67qPij5MOwGMiavStm7m3KmSWvy47/RU4mYMjOErgawgs7AwWJmuVROfzx2 XNAFVOVzW3iP6Wa5tKpbr5v0TFcNz/+zzt+KTZbMywTUIU/aq+q1xsF0diqdpFMM1vXTWsRKZ3F nBb22qEpRqeN9IKImETkT3u1I= X-Google-Smtp-Source: AGHT+IEyX2PsGwHiWh9YBXWyh9KnS2XChVqDRbjSqIfXQ4KIiOks0HRvnmeCEj9uVMrTuJxIP3mceA== X-Received: by 2002:a05:6000:18a8:b0:42b:5521:31ad with SMTP id ffacd0b85a97d-42cc1d51b1fmr22958771f8f.49.1764253465437; Thu, 27 Nov 2025 06:24:25 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH v3 2/5] vvfat: move fat_type check prior to size setup Date: Thu, 27 Nov 2025 15:24:14 +0100 Message-ID: <20251127142417.710094-3-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251127142417.710094-1-chigot@adacore.com> References: <20251127142417.710094-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::434; envelope-from=chigot@adacore.com; helo=mail-wr1-x434.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: 1764253568661019200 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. The selection of floppy size was a bit unusual: - fat-type undefined: a FAT 12 2880 Kib disk (default) - fat-type=3D16: a FAT 16 2880 Kib disk - fat-type=3D12: a FAT 12 1440 Kib disk Now, that fat-type undefined means fat-type=3D12, it's no longer possible to make that size distinction. Therefore, it's being changed for the following: - fat-type=3D12: a FAT 12 1440 Kib disk (default) - fat-type=3D16: a FAT 16 2880 Kib dis This has been choosen for two reasons: keep fat-type=3D12 the default and create a more usual size for it: 1440 Kib. The possibility to create a FAT 12 2880 KiB floppy will be added back later, through the fs-size parameter. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index dd0b3689c1..baf04e678b 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1188,28 +1188,8 @@ static int vvfat_open(BlockDriverState *bs, QDict *o= ptions, 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) { - s->fat_type =3D 12; - secs =3D 36; - s->sectors_per_cluster =3D 2; - } else { - secs =3D s->fat_type =3D=3D 12 ? 18 : 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; - } - cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; - heads =3D 16; - secs =3D 63; - } =20 + /* Verify FAT type */ switch (s->fat_type) { case 32: warn_report("FAT32 has not been tested. You are welcome to do so!"= ); @@ -1217,12 +1197,33 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, 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; } =20 + + if (floppy) { + /* Choose floppy size. 1440 KiB for FAT 12, 2880 KiB for FAT-16 */ + secs =3D s->fat_type =3D=3D 12 ? 18 : 36; + cyls =3D 80; + heads =3D 2; + } else { + /* 32MB or 504MB disk*/ + cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; + heads =3D 16; + secs =3D 63; + } + /* Reserver space for MBR */ if (partitioned) { s->offset_to_bootsector =3D 0x3f; --=20 2.43.0 From nobody Sat Nov 29 10:17:25 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=1764253565; cv=none; d=zohomail.com; s=zohoarc; b=K5JXOyjB1FH0MVDYOM8O4Mo/OgXB/EZ+Gdlkc3lliERBBpwj5lbsL6muqsbDsE2dRIUmv+3Z3TBQTaeyVY3ZUTuopzxigOiApP6Hct7nbkXS07HJ/AxRCSeP7xWazXbv/ywlzOaYeodXM8NFMzHPGWuD/ghm37JSNQsjr4cQtas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764253565; 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=V6VrcdcLzzXZfY7cDeFmaKqwoc/P/gxx140XIDfVQGE=; b=JnCrWwTUbFYPoXgCmqVUBOXIR0Sgd0TYPYnSrUPe+dV6foDQ6hshWKds9A2++osYS18YxsvTJ2BXZi2uNwtlsTsR3CPSpAzDlNIrTcW2QzOaSLSDqRLGrIg1Vln03nOa8KX92srCWo4/MoFiNdq1G2BA4veMiNDTP62XtqJpLOE= 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 1764253565415657.2184418969189; Thu, 27 Nov 2025 06:26:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOcvA-0005re-F7; Thu, 27 Nov 2025 09:24:32 -0500 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 1vOcv8-0005iD-2H for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:30 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOcv5-0006mh-Nm for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:29 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-42b31507ed8so859746f8f.1 for ; Thu, 27 Nov 2025 06:24:27 -0800 (PST) Received: from chigot-Dell.. ([2a01:e0a:ca1:4970:e598:a2f0:7cc0:4392]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca1a2easm4148996f8f.23.2025.11.27.06.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 06:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1764253466; x=1764858266; 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=V6VrcdcLzzXZfY7cDeFmaKqwoc/P/gxx140XIDfVQGE=; b=P2iFht3cmVCPB3SS8JVXPbVR9Fofo7qDPSEnfxt6ImSTq+XuXp4VjdFwWekiFyRLLf oO8tf5tiC8SkXDdxsSM6VBQ0gryRuVHxCI12rOP0eCD91rb+fK0Fnv5GFRO7ZYccqVJa yYoBp/Aw2lCaymg4IX125OkvZG7sWjjnXc5v4r1meeSQKriQwkQkFxafvsX9vMU8HtoG E9WouszgCJ1fOQGVinGPUOv0WEodqark3mK5pi7SwTxu4i9PV8ozmHf4kZucnVhnZVK5 1sAD9Brt0TTjMhbEMS80Ke0Wer/C6xcxIzQlZihJOMTPM7GlJ8C9ipMu7oHqhfQ8EFvW XqqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764253466; x=1764858266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V6VrcdcLzzXZfY7cDeFmaKqwoc/P/gxx140XIDfVQGE=; b=Zd0LAl6ry2N3Iy8rEBb0hnW17Q1tURhyLSycjtdCyK/JaswgyrcJNWNr5/sdbI1AaW D3oqWcP41NzplW6FYzOYawecCVQuX1BxzXB6r+iTMSs/modftojXuVl0qykyoGnx0e2v 02xgxSR4f+rWS3WQ8NnQG2YoraV8QjJ1oNEr3VKU5q1SuEDosCwtdp/DZSeSyt5XHK28 jKiLVOGu1mmG0AEojyjnoAvWnKNGPTz/L0LK2nc2P+b34zBMqnoBi8UujPm1Ts/eHL3n mFLoogVM3zWMQNRud4yaIW/cN4fVmKL0U0Ci9gEAV0aaj++0GpWhRYyNSv9WrGX+5DR0 qFlg== X-Gm-Message-State: AOJu0Yy6Wp5Iz8AUniLDsFJdfvdBUxwOqVJBpc+R+J3+1id9U3pliNLJ HcDd1q3YT/RrSFXL+EtKEAdN6owz08aIOISk3MXTeThP5tCnve+Nu+2dqEU/IKFAfA== X-Gm-Gg: ASbGncu9YBoiPDrl7er81M0qPU+Bv7pt12njZoLR7/B4iHwUZkrQ23lF9zuPRur01B7 EvHarHymDMccCCQgVzwanFGDM9VbhNoldPBVsKqo/vo/8Gztq7+0gwHSAy+Y1dDpaCNUjl7S+rA HNZPr8pHDey6U+EiprEvzk9EwKJNiUC7f0U1NOqp7JoBKJx80keEHtgOCnVRMelAG1iy0rPNAuK zVBQCU9FWalH8owL/iO7vaOr3WlF+1UuXkDrKLk5665CxzOY8y0O1ar0ljtvR6VL4g/EPDspPj7 uuSIEloWXajjQ7A07MK4JQQ1dQAwxqet83NOmh1ntdGj9F9QHwbKYYPORO/CG/DI3JqdAIf3zNA Z1AullYNRxl9A8eBbAJ/nUxKe9cK+VXk5AkXOec2eYR68qqCG5UIM3xw6h/Kg08b8dKQUlrTQ3I LDHZF0nAssMT8D X-Google-Smtp-Source: AGHT+IEijdoH1Zm1vEUNN8clgPnF85kUIylmBhwWOeTRyNuXxr2FDDTlpmZ7yumJg9xOxYChzb99DQ== X-Received: by 2002:a05:6000:26c2:b0:42b:3746:3b82 with SMTP id ffacd0b85a97d-42e0f3623d5mr12422172f8f.54.1764253466214; Thu, 27 Nov 2025 06:24:26 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH v3 3/5] vvfat: add a define for VVFAT_SECTOR_BITS and VVFAT_SECTOR_SIZE Date: Thu, 27 Nov 2025 15:24:15 +0100 Message-ID: <20251127142417.710094-4-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251127142417.710094-1-chigot@adacore.com> References: <20251127142417.710094-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::42d; envelope-from=chigot@adacore.com; helo=mail-wr1-x42d.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: 1764253566845019200 This removes some hardcoded 0x200 making them far clearer. This also renames some BDRV_SECTOR_* constants that were introduced during the transitions for sector-based to bytes-based block interfaces. While they have the same values, the BDRV_SECTOR_* constants are unrelated to the VVFAT sectors. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 119 ++++++++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index baf04e678b..6b038067a2 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -75,6 +75,9 @@ static void checkpoint(void); */ #define BOOTSECTOR_OEM_NAME "MSWIN4.1" =20 +#define VVFAT_SECTOR_BITS 9 +#define VVFAT_SECTOR_SIZE (1ULL << VVFAT_SECTOR_BITS) + #define DIR_DELETED 0xe5 #define DIR_KANJI DIR_DELETED #define DIR_KANJI_FAKE 0x05 @@ -300,7 +303,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 * VVFAT_SECTOR_SIZE]; =20 int fat_type; /* 16 or 32 */ array_t fat,directory,mapping; @@ -690,11 +693,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 * VVFAT_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 * VVFAT_SECTOR_SIZE / s->fat.item_size = - 1); } memset(s->fat.pointer,0,s->fat.size); =20 @@ -902,19 +905,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 * VVFAT_SECTOR_SIZE); =20 - s->cluster_size=3Ds->sectors_per_cluster*0x200; + s->cluster_size =3D s->sectors_per_cluster * VVFAT_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*(VVFAT_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 * VVFAT_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; @@ -1012,12 +1015,13 @@ 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 + * VVFAT_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(VVFAT_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 */ @@ -1310,7 +1314,7 @@ fail: =20 static void vvfat_refresh_limits(BlockDriverState *bs, Error **errp) { - bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; /* No sub-sector I/O */ + bs->bl.request_alignment =3D VVFAT_SECTOR_SIZE; /* No sub-sector I/O */ } =20 static inline void vvfat_close_current_file(BDRVVVFATState *s) @@ -1496,21 +1500,23 @@ vvfat_read(BlockDriverState *bs, int64_t sector_num= , uint8_t *buf, int nb_sector if (s->qcow) { int64_t n; int ret; - ret =3D bdrv_co_is_allocated(s->qcow->bs, sector_num * BDRV_SE= CTOR_SIZE, - (nb_sectors - i) * BDRV_SECTOR_SIZE= , &n); + ret =3D bdrv_co_is_allocated(s->qcow->bs, + sector_num * VVFAT_SECTOR_SIZE, + (nb_sectors - i) * VVFAT_SECTOR_SIZ= E, + &n); if (ret < 0) { return ret; } if (ret) { DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64 " 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) { + n >> VVFAT_SECTOR_BITS)); + if (bdrv_co_pread(s->qcow, sector_num * VVFAT_SECTOR_SIZE, + n, buf + i * VVFAT_SECTOR_SIZE, 0) < 0) { return -1; } - i +=3D (n >> BDRV_SECTOR_BITS) - 1; - sector_num +=3D (n >> BDRV_SECTOR_BITS) - 1; + i +=3D (n >> VVFAT_SECTOR_BITS) - 1; + sector_num +=3D (n >> VVFAT_SECTOR_BITS) - 1; continue; } DLOG(fprintf(stderr, "sector %" PRId64 " not allocated\n", @@ -1518,19 +1524,20 @@ 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 * VVFAT_SECTOR_SIZE, + &(s->first_sectors[sector_num * VVFAT_SECTOR_SIZE]), + VVFAT_SECTOR_SIZE); } else if (sector_num < s->offset_to_fat + s->sectors_per_fat)= { - memcpy(buf + i * 0x200, - &(s->fat.pointer[(sector_num - - s->offset_to_fat) * 0x200]), - 0x200); + memcpy(buf + i * VVFAT_SECTOR_SIZE, + &(s->fat.pointer[(sector_num - s->offset_to_fat) + * VVFAT_SECTOR_SIZE]), + VVFAT_SECTOR_SIZE); } else if (sector_num < s->offset_to_root_dir) { - memcpy(buf + i * 0x200, + memcpy(buf + i * VVFAT_SECTOR_SIZE, &(s->fat.pointer[(sector_num - s->offset_to_fat - - s->sectors_per_fat) * 0x200]), - 0x200); + - s->sectors_per_fat) + * VVFAT_SECTOR_SIZE]), + VVFAT_SECTOR_SIZE); } } else { uint32_t sector =3D sector_num - s->offset_to_root_dir, @@ -1538,10 +1545,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 * VVFAT_SECTOR_SIZE, 0, VVFAT_SECTOR_SIZE); continue; } - memcpy(buf+i*0x200,s->cluster+sector_offset_in_cluster*0x200,0= x200); + memcpy(buf + i * VVFAT_SECTOR_SIZE, + s->cluster + sector_offset_in_cluster * VVFAT_SECTOR_SI= ZE, + VVFAT_SECTOR_SIZE); } } return 0; @@ -1553,12 +1562,12 @@ vvfat_co_preadv(BlockDriverState *bs, int64_t offse= t, int64_t bytes, { int ret; BDRVVVFATState *s =3D bs->opaque; - uint64_t sector_num =3D offset >> BDRV_SECTOR_BITS; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + uint64_t sector_num =3D offset >> VVFAT_SECTOR_BITS; + int nb_sectors =3D bytes >> VVFAT_SECTOR_BITS; void *buf; =20 - assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(offset, VVFAT_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(bytes, VVFAT_SECTOR_SIZE)); =20 buf =3D g_try_malloc(bytes); if (bytes && buf =3D=3D NULL) { @@ -1824,8 +1833,8 @@ cluster_was_modified(BDRVVVFATState *s, uint32_t clus= ter_num) for (i =3D 0; !was_modified && i < s->sectors_per_cluster; i++) { was_modified =3D bdrv_co_is_allocated(s->qcow->bs, (cluster2sector(s, cluster_num= ) + - i) * BDRV_SECTOR_SIZE, - BDRV_SECTOR_SIZE, NULL); + i) * VVFAT_SECTOR_SIZE, + VVFAT_SECTOR_SIZE, NULL); } =20 /* @@ -1979,8 +1988,8 @@ get_cluster_count_for_direntry(BDRVVVFATState* s, dir= entry_t* direntry, const ch int res; =20 res =3D bdrv_co_is_allocated(s->qcow->bs, - (offs + i) * BDRV_SECTOR_SI= ZE, - BDRV_SECTOR_SIZE, NULL); + (offs + i) * VVFAT_SECTOR_S= IZE, + VVFAT_SECTOR_SIZE, NULL); if (res < 0) { return -1; } @@ -1989,9 +1998,9 @@ get_cluster_count_for_direntry(BDRVVVFATState* s, dir= entry_t* direntry, const ch if (res) { return -1; } - res =3D bdrv_co_pwrite(s->qcow, offs * BDRV_SECTOR= _SIZE, - BDRV_SECTOR_SIZE, s->cluster_= buffer, - 0); + res =3D bdrv_co_pwrite(s->qcow, offs * VVFAT_SECTO= R_SIZE, + VVFAT_SECTOR_SIZE, + s->cluster_buffer, 0); if (res < 0) { return -2; } @@ -2169,7 +2178,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 VVFAT_SECTOR_SIZE * s->sectors_per_fat; s->fat2 =3D g_malloc(size); memcpy(s->fat2, s->fat.pointer, size); } @@ -2566,7 +2575,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, VVFAT_SECTOR_SIZE)); =20 if (ret < 0) { qemu_close(fd); @@ -2945,7 +2955,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, VVFAT_SECTOR_SIZE * s->sectors_per_fat= ); =20 /* recurse direntries from root (using bs->bdrv_pread) */ ret =3D commit_direntries(s, 0, -1); @@ -3009,14 +3019,15 @@ DLOG(checkpoint()); * used to mark volume dirtiness */ unsigned char *bootsector =3D s->first_sectors - + s->offset_to_bootsector * 0x200; + + s->offset_to_bootsector + * VVFAT_SECTOR_SIZE; /* * 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 < VVFAT_SECTOR_SIZE; i++) { if (i !=3D reserved1_offset && bootsector[i] !=3D buf[i]) { fprintf(stderr, "Tried to write to protected bootsector\n"= ); return -1; @@ -3071,7 +3082,9 @@ 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 + VVFAT_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 */ @@ -3097,8 +3110,8 @@ DLOG(checkpoint()); * Use qcow backend. Commit later. */ DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, = nb_sectors)); - ret =3D bdrv_co_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, buf, 0); + ret =3D bdrv_co_pwrite(s->qcow, sector_num * VVFAT_SECTOR_SIZE, + nb_sectors * VVFAT_SECTOR_SIZE, buf, 0); if (ret < 0) { fprintf(stderr, "Error writing to qcow backend\n"); return ret; @@ -3124,12 +3137,12 @@ vvfat_co_pwritev(BlockDriverState *bs, int64_t offs= et, int64_t bytes, { int ret; BDRVVVFATState *s =3D bs->opaque; - uint64_t sector_num =3D offset >> BDRV_SECTOR_BITS; - int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + uint64_t sector_num =3D offset >> VVFAT_SECTOR_BITS; + int nb_sectors =3D bytes >> VVFAT_SECTOR_BITS; void *buf; =20 - assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(offset, VVFAT_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(bytes, VVFAT_SECTOR_SIZE)); =20 buf =3D g_try_malloc(bytes); if (bytes && buf =3D=3D NULL) { @@ -3195,7 +3208,7 @@ static int enable_write_target(BlockDriverState *bs, = Error **errp) =20 opts =3D qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abor= t); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, - bs->total_sectors * BDRV_SECTOR_SIZE, &error_abort= ); + bs->total_sectors * VVFAT_SECTOR_SIZE, &error_abor= t); qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:", &error_abort); =20 ret =3D bdrv_create(bdrv_qcow, s->qcow_filename, opts, errp); --=20 2.43.0 From nobody Sat Nov 29 10:17:25 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=1764253548; cv=none; d=zohomail.com; s=zohoarc; b=nkNIiDpx8NjI6FbXLMHDKy0jlfFW9bVrXWBnZBdg4qb8l2MS8Hs5KKY767IraARjtTzu1F5VoaEPQT3VlKt1QCyGL31Q4UGcHfStpxQe+ptj4aGwhfunOe1IOdeSMCCAs1S2h1aJTToaHNBcBkZJtpsuHTVigJIXV2neIH39Iqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764253548; 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=UyvHnJ6oHl1zC+JyET4uSk+rALdJgL29skdh/h9NP3I=; b=H25KsRXjdh4fG4/7OOL1BneyOb8zTya7sKeyy3SO4FItEDMdvW+Fld+RBJK7toPyl+qJ/utB7C1ZdNFGVuCpAqvW59x0adEU/jo2DEsfrTSazGl25YBVVWiLMpoSEdnJJmEiDx753JC0AFwD0rK35tVqD954+g55mpLdYqqbewU= 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 1764253547982525.7916606797999; Thu, 27 Nov 2025 06:25:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOcvC-0005uw-81; Thu, 27 Nov 2025 09:24:34 -0500 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 1vOcv8-0005ia-6g for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:30 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOcv6-0006nB-Gu for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:29 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-42b32900c8bso634689f8f.0 for ; Thu, 27 Nov 2025 06:24:28 -0800 (PST) Received: from chigot-Dell.. ([2a01:e0a:ca1:4970:e598:a2f0:7cc0:4392]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca1a2easm4148996f8f.23.2025.11.27.06.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 06:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1764253467; x=1764858267; 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=UyvHnJ6oHl1zC+JyET4uSk+rALdJgL29skdh/h9NP3I=; b=Zl8FKdEfo5KbgAsrHbJ4WCsTA62D2+u4IxA/7P3FTz7CwvQUDd1Srk/qMckjVVEiDX ZOKv58D8xjMyJXZixoZYwH65bfZoa78qBcB67CSbwXgnI7V3ZFVX88fDHTtvDGclipKY seCIB8A6Re+cAY6ZPXqHs9/URoUGACMAVu5sebXAYEbB00vEDePlTQyfoVGSBgk3C6bX cV8HG0OPCrR/lYTLlByUlpd03XM78NEz7Y9K0AKIOyTlxSxiMPy6q3kHUnW1QZHL9cfe 6NMPMAgHUqfI0EXnQ5kLjAOtHNGvkKwJMCnva1YK/eKf7fPmZY+kKQ6a9ETaY8639LrF DO7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764253467; x=1764858267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UyvHnJ6oHl1zC+JyET4uSk+rALdJgL29skdh/h9NP3I=; b=Biw4aXGMqfMTmXSP8DadKFfIUCryJvcpOMjWy2wn314d422czcDS5NBorSurmFVYJy UwEC51GE/c/o3EOb0m1uExVj6e7nb4QFA3nUe0njxlwwqKIcyeQGMNSRvabf9gIyhME1 t60TtqLirPOvQOQbc6+8Z0W6gs60p0j03rv1/tNKYWIVRQU1MxVdkltr9wJs1s9zF/dR ElZnT7TphpVqwyy6NWmkwz+NH7vZFiLFAAUubza7igE1tcJ/22E3s2HsukZ8TUdyjJIc MfvT6Kx1kP36nosZ5xv0t61Bmq9DFu+xH69JoyJ5djr3M3Hgqk9iCNxY1MTF/6ChaMg5 hpdA== X-Gm-Message-State: AOJu0YwxljSUwqndvbWpStnMF8e1dxtwP/xXZZwqTILnwI7NhZXltQ1V 7FbhmfkD9uSBPL9PBZ+z7ecazZtCYA1uniaFnjD5y3JJzTUrJ4+E/guDqKGo35Q26w== X-Gm-Gg: ASbGncvQsuIDZ+dNysxr2Jf1CMFGVZUM//ROGddy4QWcIr8iuZQyZDsvQ5lNbHFS/S2 S5RD19wSFjcBDtm9S9fpQINUUcwIZJcX8NJaSTP7UV2FCnu5zF7S2dtZ42HCf5AtvOGxqxsnuFW Cco9E9F9KQS4sC9Z71Teioo2zlClKQRX2AXu0baFhKSogRkizAqQd8Q/FHIFG1XXZyT0j+aIZ4a 0l6IaF2T1yhlvuS1toyt10uH+Cit1Ckb1xwpoQNoXMcdwC9aDBst/P+sUpxW2vPnYYZYM0buEUQ XvbHScrtoXtXlD5/oexTm0vbYTFcq/mqMkWf9BxMtO58kxEgw71sijgrh4ArmWy9dA+hDh5MJF2 99MBQM+cajuzhL57WeYmIFodS1hQFKhaa3zrIM8w6qKvcH2uOh/RFbiIwPvE1SrBiID/SwH+kYn K+RzBKmV5ed2yO X-Google-Smtp-Source: AGHT+IFmPHyhy5tDE3OSx73cTtJYxk9DD0PBtSFTWar6LORVKYa6nVAX+6ZeL7tl3c8Ma0T4DWa+qw== X-Received: by 2002:a05:6000:2681:b0:42b:4177:7139 with SMTP id ffacd0b85a97d-42cc1d520famr25070105f8f.46.1764253467029; Thu, 27 Nov 2025 06:24:27 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH v3 4/5] vvfat: move size parameters within driver structure Date: Thu, 27 Nov 2025 15:24:16 +0100 Message-ID: <20251127142417.710094-5-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251127142417.710094-1-chigot@adacore.com> References: <20251127142417.710094-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::42f; envelope-from=chigot@adacore.com; helo=mail-wr1-x42f.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: 1764253548842019200 At the same time, rename them to match bootsector fields. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 6b038067a2..4e698f1ca7 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -312,7 +312,10 @@ typedef struct BDRVVVFATState { /* 0x3f for partitioned disk, 0x0 otherwise */ uint32_t offset_to_bootsector; =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; @@ -366,7 +369,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; @@ -382,9 +385,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); @@ -896,8 +899,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; @@ -1031,8 +1033,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 @@ -1147,7 +1149,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, partitioned; const char *dirname, *label; QemuOpts *opts; @@ -1218,14 +1219,14 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, =20 if (floppy) { /* Choose floppy size. 1440 KiB for FAT 12, 2880 KiB for FAT-16 */ - secs =3D s->fat_type =3D=3D 12 ? 18 : 36; - cyls =3D 80; - heads =3D 2; + s->sectors_per_track =3D s->fat_type =3D=3D 12 ? 18 : 36; + s->cylinders =3D 80; + s->number_of_heads =3D 2; } else { /* 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 /* Reserver space for MBR */ @@ -1246,10 +1247,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)) { @@ -1270,7 +1274,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; } @@ -1291,7 +1295,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.43.0 From nobody Sat Nov 29 10:17:25 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=1764253548; cv=none; d=zohomail.com; s=zohoarc; b=fypI7+K8PSl1srtTlPslXtu/g8HiO8orCFLV/R1tNSTqbVhlJVFNKLG5EsgBQ6TahxUzV8yZq2UGJSrZTrtdN+enDECxfnTwqymgMu+IPMZurgYFsHRq0yuAeJ0RFn4atkMCk8MfXBUn1zHX7Kd6DdQ7wAqfZZcvW9q6GJkp3Ec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764253548; 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=lI/ueV3yXfasYkKZLg6niVJzElYESndcDgMuV6p/Zq0=; b=gG/p18Wn+X+h87VJcT/rJggpWNs2RTWl9iIdRrjnoDCCjIBXJaukhqNUCmtTKMCvuQ32yL7ZPmkcdAU4D2m4O1dDQEUtT9zb2pLY/NahMCn80BANwe1BTfPE9ZoMGVwH6nFlClZVAoaHENh5i4veNYtPYpw+lfZSO4dm59CdSBA= 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 1764253548201962.3926332878065; Thu, 27 Nov 2025 06:25:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOcvD-0005yb-HD; Thu, 27 Nov 2025 09:24:36 -0500 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 1vOcv9-0005pb-RM for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:32 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vOcv7-0006ng-By for qemu-devel@nongnu.org; Thu, 27 Nov 2025 09:24:31 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-477770019e4so6910175e9.3 for ; Thu, 27 Nov 2025 06:24:28 -0800 (PST) Received: from chigot-Dell.. ([2a01:e0a:ca1:4970:e598:a2f0:7cc0:4392]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42e1ca1a2easm4148996f8f.23.2025.11.27.06.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 06:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1764253468; x=1764858268; 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=lI/ueV3yXfasYkKZLg6niVJzElYESndcDgMuV6p/Zq0=; b=I31kDAdVGWlT/CTcmOdllqrdtKbcnJ6+oltvcJPDNg4htzZTILv7JAc9+AQY2D+ASz +xfOD1SPFVgWpf06k4nzQXKpvLhxPiW8ne4syGvv/s4fz6/s7WF7srAVHzoSrLTTaxKK CKL3d5rfAGTQ5qInTlbYJbLSxuD/VX/PuirdSnxwXouNk2IxMrKbNzvZyiIGL9/QN4kK doTxybPsSRckoePHQ9o5aDeFW4ifn+CfasIJU3bZLFDNgksR8U+IbmY0BaJ+jQDfKBxW BwD5yptPArpnqa1eKDHweQZ8eJmKmXEvDJ/+h2xyRD96bNXMDoCxfhLnpEGSJQQpxKr6 KH1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764253468; x=1764858268; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lI/ueV3yXfasYkKZLg6niVJzElYESndcDgMuV6p/Zq0=; b=N2AhO+KkFgCkXKUDuEsp722Kb1T928fhP5Tvo+FIFlBtVfANONzK3hVpaNDTRHRslT o2ZErzVtOK/cjb2iSDnMODPP67qeEAUItp2xK6JJhvhMABf7+tIcs35ALZ46voAi3P3h Da1DHMNkrFMfhCMvvX/d5XqZsunc/+CK5UVlyF9ZoCl0zVH77ccFiq9mRC5o/mUEtyYL 5EvjfVSAIiSUr5Z8dXfkuyfgMsz5HUx2SsKRlpynKLX22FMQCeilcd8ZQV9PP9yJdbMY Of6ZwxiS6hVTPqjrSWD+eqQ5XWpKaIWbMHc+FktyeQ/KN8sd/tPIIqxIKwYNHJ5GOTSv VXXg== X-Gm-Message-State: AOJu0Yw9Sm64J1oluS1vNg8wluroorG6GHkSWKZV3SbU7fvDpjeSlArN wL4pgL+UVE567DLlD4/JV+t4CA0TDvbZyE1VJ2N/erwgvl6XpPC8MzGuv7HkNu7t1Q== X-Gm-Gg: ASbGncsBxf0Ar8uwyw1S7TUDJhrJV3H6j5j+8flwB5JJ/RWbca3jBoYlxH0sEIqfHGy ZkAg4bo7xq1JZnKQR66GiCcNH0Uj6GAMONhNa7Vj5CRiUCwHcIKoMfVXzU7epmkti8vXROp4UHt Db7b0pSZOJCDpmrCVtUrOVSdjHQu8sDO9pM5HSa+1NfKUJF2bUzn53YiT4u47eB59gruLAY8opx lVNwcRt16URx+JE4ITzyBF+O0oTq1UU5GIT/DBbopT+IZm3R0AV1cPt85fTD+5sxoMOe3fL4bvM wcVMobxiiFBF+IzXkn2tuP0Ylx0EQoVcYBz7Yw5+PdjuECwSsEWk67Xc7b0PN6JFggNG4Fti9cv n7/p80eEZiaT9ywXbGfqpYpEKNyZO3GS8ZdTRLqH/6BMDu5lSM42xRFLQyioIVavHogQ8/XPx/0 7Co9KF2DcRBe79 X-Google-Smtp-Source: AGHT+IGIIR9q32Z5G45M/pKVUmqgb3GK5vgoZTXI+WSqgE+2BxxmSH9dT7BsdMyiHbfMjI3tZa4cdA== X-Received: by 2002:a05:600c:3b0a:b0:477:9574:d641 with SMTP id 5b1f17b1804b1-47904b1b2ecmr98412945e9.22.1764253467836; Thu, 27 Nov 2025 06:24:27 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH v3 5/5] vvfat: add support for "fs-size" option Date: Thu, 27 Nov 2025 15:24:17 +0100 Message-ID: <20251127142417.710094-6-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251127142417.710094-1-chigot@adacore.com> References: <20251127142417.710094-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::335; envelope-from=chigot@adacore.com; helo=mail-wm1-x335.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: 1764253550782019200 This allows more flexibility to vvfat backend. The values of "Number of Heads" and "Sectors per track" are based on SD specifications Part 2. Due to the FAT architecture, not all sizes are reachable. Therefore, it could be round up to the closest available size. FAT32 has not been adjusted and thus still default to 504 Mib. For floppy, only 1440 Kib and 2880 Kib are supported. The name of the option was made different from the classical "size" on purpose. This would avoid hardly-detactable errors when "format=3Dvvfat" is forgotten; "size" being recognized by the default format "raw". Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 163 +++++++++++++++++++++++++++++++++++++++---- qapi/block-core.json | 8 ++- 2 files changed, 155 insertions(+), 16 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 4e698f1ca7..f763ba6423 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1094,6 +1094,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 "fs-size", + .type =3D QEMU_OPT_SIZE, + .help =3D "Virtual disk size" + }, { /* end of list */ } }, }; @@ -1145,10 +1150,150 @@ static void vvfat_parse_filename(const char *filen= ame, QDict *options, qdict_put_bool(options, "rw", rw); } =20 +static void vvfat_get_size_parameters(uint64_t size, BDRVVVFATState *s, + bool floppy, Error **errp) +{ + if (floppy) { + if (s->fat_type =3D=3D 16) { + /* The default for floppy FAT 16 is 2880 KiB */ + if (!size) { + size =3D 2880 * 1024; + } + + if (size !=3D 2880 * 1024) { + error_setg(errp, + "floppy FAT16 unsupported size; only support " + "2880 KiB"); + } + + } else { + /* The default for floppy FAT 12 is 1440 KiB */ + if (!size) { + size =3D 1440 * 1024; + } + + if (size !=3D 2880 * 1024 && size !=3D 1440 * 1024) { + error_setg(errp, + "floppy FAT12 unsupported size; only support " + "1440 KiB or 2880 KiB"); + } + + } + + if (s->fat_type =3D=3D 12) { + if (size =3D=3D 2880 * 1024) { + s->sectors_per_track =3D 36; + } else { + s->sectors_per_track =3D 18; + } + } else { + s->sectors_per_track =3D 36; + } + + s->sectors_per_cluster =3D 0x10; + s->cylinders =3D 80; + s->number_of_heads =3D 2; + } else { + + switch (s->fat_type) { + case 32: + /* TODO FAT32 adjust */ + if (size) { + warn_report("size parameters not supported with FAT32;" + "default to 504 MiB."); + } + s->cylinders =3D 1024; + s->number_of_heads =3D 16; + s->sectors_per_cluster =3D 0x10; + s->sectors_per_track =3D 63; + return; + + 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 32 M= iB"); + } + + s->sectors_per_cluster =3D 0x10; + s->cylinders =3D 64; + + /* + * Based on CHS Recommandation table: + * Card Capacity | Number of Headers | Sectors per track + * 2 MiB | 4 | 16 + * 4 MiB | 8 | 16 + * 8 MiB | 16 | 16 + * 16 MiB | 2 | 32 + * 32 MiB | 4 | 32 + * + * For 2 MiB, the recommendation is 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; + } + + break; + + case 16: + /* Default is 504 MiB */ + if (!size) { + size =3D 504 * 1024 * 1024; + } else if (size / 1024 > 4 * 1024 * 1024) { + error_setg(errp, "FAT16 unsupported size; higher than 4 Gi= B"); + } + + s->sectors_per_cluster =3D 0x10; + s->cylinders =3D 1024; + + /* + * Based on CHS Recommandation table: + * Card Capacity | Number of Headers | Sectors per track + * 64 MiB | 4 | 32 + * 128 MiB | 8 | 32 + * 256 MiB | 16 | 32 + * 504 MiB | 16 | 63 + * 1008 MiB | 32 | 63 + * 2016 MiB | 64 | 63 + */ + if (size <=3D 256 * 1024 * 1024) { + s->sectors_per_track =3D 32; + } else { + s->sectors_per_track =3D 63; + } + + break; + } + + /* + * The formula between the size (in bytes) and the parameters are: + * size =3D VVFAT_SECTOR_SIZE * sectors_per_track * number_of_hea= ders * + * cylinders + * + */ + s->number_of_heads =3D size / s->sectors_per_track / + VVFAT_SECTOR_SIZE / s->cylinders; + + /* Round up to the closest size if the given one cannot be reached= . */ + if (size % + (s->sectors_per_track * VVFAT_SECTOR_SIZE * s->cylinders) !=3D= 0) { + s->number_of_heads++; + } + + } +} + static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVVVFATState *s =3D bs->opaque; + uint64_t size; bool floppy, partitioned; const char *dirname, *label; QemuOpts *opts; @@ -1175,6 +1320,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, "fs-size", 0); =20 /* Hard disk are partitioned by default; floppy aren't. */ partitioned =3D qemu_opt_get_bool(opts, "partitioned", floppy ? false = : true); @@ -1216,18 +1362,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *o= ptions, int flags, goto fail; } =20 - - if (floppy) { - /* Choose floppy size. 1440 KiB for FAT 12, 2880 KiB for FAT-16 */ - s->sectors_per_track =3D s->fat_type =3D=3D 12 ? 18 : 36; - s->cylinders =3D 80; - s->number_of_heads =3D 2; - } else { - /* 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; - } + vvfat_get_size_parameters(size, s, floppy, errp); =20 /* Reserver space for MBR */ if (partitioned) { @@ -1236,9 +1371,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, =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; @@ -3277,6 +3409,7 @@ static const char *const vvfat_strong_runtime_opts[] = =3D { "label", "rw", "partitioned", + "fs-size", =20 NULL }; diff --git a/qapi/block-core.json b/qapi/block-core.json index ca438fba51..fa4df7b408 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3478,11 +3478,17 @@ # (default: true for hard disk, false for floppy) # (since 10.2) # +# @fs-size: size of the device in bytes. Due to FAT underlying +# architecture, this size can be rounded up to the closest valid +# size. +# (since 10.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsVVFAT', 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', - '*label': 'str', '*rw': 'bool', '*partitioned': 'bool' } } + '*label': 'str', '*rw': 'bool', '*partitioned': 'bool', + '*fs-size': 'int' } } =20 ## # @BlockdevOptionsGenericFormat: --=20 2.43.0