From nobody Sat Nov 29 10:48:49 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