From nobody Fri Nov 14 15:22:08 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=1762527253; cv=none; d=zohomail.com; s=zohoarc; b=hc/AsXivRnMbCmT8T+AhckOq4vnGOA7ZZPCCuxKGRvO91OlsqJTNEZsL3cRXZneqUzXvsvcoL0BhRSuNiOgLLlcBt7aga8vzUfDMhU8Mu5uKLXzj/SsswHMLefDxmeZHL0VA6mSxk53wd9QhagiOscQUqJ1UUAbLnW2vJ+p217Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762527253; 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=izy7/qPzPQoipaFGeT4gnLUB0venGvr75VtHiWV0UpE=; b=iT1yIxzLSNg3mWUdDcxwmB8IUDVXTmw6fY2IzKxP4iOEUszfxpai2Hs2xLRPZm9FFTbdoFKi7JYRTXyTgSECFGjNMING6vcfaRZkdYK1sYU0MHhJe6Jw4Qt5IXgVT5X2eqa3+G7eAWhLlyBmRCZF9vebiMvgEAzDeNCtqoVGDV4= 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 1762527253627802.7875433150627; Fri, 7 Nov 2025 06:54:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHNqU-0003hW-8d; Fri, 07 Nov 2025 09:53:46 -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 1vHNqK-0003Ra-KW for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:36 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vHNqH-0001tw-74 for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:35 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-429c8632fcbso574664f8f.1 for ; Fri, 07 Nov 2025 06:53:32 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:e453:acd:db85:b66e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63e131sm5922435f8f.20.2025.11.07.06.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1762527211; x=1763132011; 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=izy7/qPzPQoipaFGeT4gnLUB0venGvr75VtHiWV0UpE=; b=JDOClDWblSY32a8MSvybJqHK3t2KwT1q4OFBEBWbR7mls7yuQz91/V6iayiYp4rWY/ IFIOUqNafMspdIj1vWW3yTM/r1QMsjgOeGS56JoOJuxtyfJOFYiUZPLiJ5vjXzDY/SAh Jo6vw8Z3iY9tY+PcEZnuFTtZi5yKCe40zqTGmbL6MazlknmAlBRQRftcdFIE4qergGrQ 8/J1Q42ySsXce2n5tnf3EvBbJY3YWalz0tSVwX+JKfOqj3zs+t5165ZHuCika7szn28T d5QrIcdnj+IWgavVIY5Vfd+gIQTxsDjLYF2Q2Bb9KVFpiwbTKhDs56yUT+S7kn62ZulA 9C+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762527211; x=1763132011; 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=izy7/qPzPQoipaFGeT4gnLUB0venGvr75VtHiWV0UpE=; b=uHRABxrxZOMopSjaiY39gfS8UHpXol+lhwGZBjptCgDigaE+qCs42NEVoFrfyTJiwi CowsgMoJfW4Y2hkulldNqQmFBykZ/LLA9tQjJu253Mlc3tu0LllM7Md1j1CTYS/VeWBl Jme4A6BEpwqwFdDtN2wY5pu5NzLT/tMp+N4/qEnaJqWzTNJW/AGJfSGhM5AFcuTBi7RN fSoKGxH3ikojKnAInfzxSfHDprZcohRXTXxVD44yUkyiz4qfYQNfgEJVI3w1Wvl+UiZP OMBdhB9q43IpVsJeUv/C0srvF63lXPdjTj2vEG/c+hwMkxGgrFRfrV4amauRX+ThmLTk SoKA== X-Gm-Message-State: AOJu0YzqPa9hOLmE91TIg5DTGuQTKfRBHzWVAXcVZLjZqxXaQ8Sjdwty nqqZXqup8TRYCE2mHyfabgrd7ty+Xc5Grrj0ATx9f9JHi6Cy1Mc+vfQh0AmCmfDDNA== X-Gm-Gg: ASbGncvlGxZo8Jpu1wbuscU//Dr1RXWwUx8p2Jv+drquxOykY7KgA7sjCkwpEdENs0H 406L4UDXJsw2p0xry8AywsbXyOLsRHqPmAdgyQmaTZ+dsh2ZkrcCzMtcm2Bw7EH9SXQL7za0jrz LD6/hQaXY5x8vj4kCmC0awXCDlAYv8RfrO1LtnHqVGXeuqqG50vXpe7mR9nJoCrROtnTMjnpVGF Tx6UUtgG0Krggj1w0k6eGjWM6yS5KbuDDCYeJ2s4oSYOVWEXLmyge0IMhJQT6e0Y+Plk3Kdwagb QmDUAmaSUyGH+OLdte62uuyKcsqs/MGb4+HMew/QXqyUvQLya9pk5h+WytJ7+wcUxxy4SaTixml WuxRKxL+ScrxZS2XMKml7VwYRdcM8KfWOLfGTRsw9fRhhZfujdNtiQv2u4jmLrwgcKwr5JxL5Gk t0gGX7IdE= X-Google-Smtp-Source: AGHT+IFmIv057xjnjIyUjYmI6jz+jSUOzHJNO7gZIIdGv9cWlh+CWydPo7XQNDYBm87fBaOk79rOnw== X-Received: by 2002:a05:6000:258a:b0:429:cda2:a025 with SMTP id ffacd0b85a97d-42ae58b14fbmr3400600f8f.13.1762527211131; Fri, 07 Nov 2025 06:53:31 -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 v2 1/5] vvfat: introduce partitioned option Date: Fri, 7 Nov 2025 15:53:23 +0100 Message-ID: <20251107145327.539481-2-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107145327.539481-1-chigot@adacore.com> References: <20251107145327.539481-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::429; envelope-from=chigot@adacore.com; helo=mail-wr1-x429.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: 1762527255859158500 This option tells whether a hard disk should be partitioned or not. It defaults to true and have the prime effect of preventing 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 | 21 +++++++++++++++++++-- qapi/block-core.json | 10 +++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 814796d918..de6031db98 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,12 @@ static QemuOptsList runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Make the image writable", }, + { + .name =3D "partitioned", + .type =3D QEMU_OPT_BOOL, + .def_value_str =3D "true", + .help =3D "Do not add a Master Boot Record on this disk", + }, { /* end of list */ } }, }; @@ -1092,6 +1099,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 partitioned =3D true; int i; =20 if (!strstart(filename, "fat:", NULL)) { @@ -1116,6 +1124,10 @@ static void vvfat_parse_filename(const char *filenam= e, QDict *options, rw =3D true; } =20 + if (strstr(filename, ":unpartitioned:")) { + partitioned =3D false; + } + /* Get the directory name without options */ i =3D strrchr(filename, ':') - filename; assert(i >=3D 3); @@ -1131,6 +1143,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, "partitioned", partitioned); } =20 static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, @@ -1196,7 +1209,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, "partitioned", true)) { + s->offset_to_bootsector =3D 0x3f; + } cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; heads =3D 16; secs =3D 63; @@ -3246,6 +3262,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..8a479ba090 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 a hard disk will be partitioned +# (default: true) +# (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 Fri Nov 14 15:22:08 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=1762527255; cv=none; d=zohomail.com; s=zohoarc; b=WIZGux6/CadXi3nIWu3NdR+PWJLRSWls+D7uBGov1/AuAvxoYrT7XdSbiUZymx34YPVk1auQAlL8QNPg+BzNcxNyADhq6DdQR7d4uA4qcvuxG6jJBbI39AZPBX3btzKZPnphyxpyBJw08BHGTJ7ZBfyoxzyyzk2xO5w97PpiHtI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762527255; 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=NQ4FOUgzu/5ncAghYllBlZW5m3sSyvsHiRGMiimwX3M=; b=AJo8UgSrDPzLhuUw13Epj3ZysYPZU0nR4pzR/QSeFgOKQEtAWQfPtJDMp3oN6lgRhlNhRN42DIh+SqN5DOjDhFySaNIW4+sL4UvIRem4/ZandwRsEXmidpORK1EVbPZ9M0edeZjAMCI1jf4dQlAfFpc6Ih+j6990EiH6UnR/Y/Y= 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 1762527255052718.5439222975245; Fri, 7 Nov 2025 06:54:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHNqS-0003eS-Ni; Fri, 07 Nov 2025 09:53:44 -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 1vHNqK-0003Rc-K7 for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:36 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vHNqH-0001uO-Bn for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:35 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-429bf011e6cso839062f8f.1 for ; Fri, 07 Nov 2025 06:53:32 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:e453:acd:db85:b66e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63e131sm5922435f8f.20.2025.11.07.06.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1762527212; x=1763132012; 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=NQ4FOUgzu/5ncAghYllBlZW5m3sSyvsHiRGMiimwX3M=; b=fVkcQ31ZJqGc6bEzYPq14kRZ40ypuYAafbEBsn7gkYkb8tOI5gBxM07iOESQIfRyWe nq3dgxF8o2kZi0I6ZhpC9x1JKSnwyqz1Gvho3vwr9FemV19z6fhqItV91jaQFFLDr96W mOhhygDytXHilqVkntzvNQx9C6WJ7gKOOJmenG7eXbOiQSsbB3VU4UiquxhQAcnFgr54 HyIVIAASjz7XdN7vSpD1fG/hWWYknR2ohtHHMr1lBGC9784yAC/uMVYSHBiad2Mq0ou6 eE/KmiMzq/Prr+7F8T7cH+zhh0V3iKjsRdPrEByWRdRzj4yrlQizJUtrSyhs3Vi8O3CX oKnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762527212; x=1763132012; 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=NQ4FOUgzu/5ncAghYllBlZW5m3sSyvsHiRGMiimwX3M=; b=IE+SLYc66dOOM1zl1c3EhIzPjUsQX5R5fHdw2AkoFUy/xet8Hhkh9VE7u4VA6A30bE tt6j2Q6h2kHf81d61Ndr+WcrC91/7Lk4TvzBAS5hYiTTZn2bv/c+979bHECodDJkFskX 4BEvDI1MdnCPIuLzhBwp/jRSX5VDLD9OQIPCUHhSc9dY8Q882iZ8NRjYxodzyuJ3Q8gy 3+2thQFbV5GEuad83F6/S1c2LiDgiDpkZ94xNPY0XLhTx4k07/bFrzKeaXF26i40Z3tq m+69A/1LAgQYsdjr4Am2N2euVS2gxofj2XVRKV8LgXItwJyWDW5yTqyeIIyg2CpgPDol 2s6w== X-Gm-Message-State: AOJu0Ywv6CDgKBTSiJPpSY5iS2WVC8r74Fr3kWba30hVDdKJ1CORhQ3b QH8P9ZOtULbYF0pNjmOVq7Hc/rZb5OiURb6WN0dYUbBRSXnRsgj3JkPqCXa6WZtH8kjdwnT7F8t Su5w= X-Gm-Gg: ASbGncuRrBYpamakbeTMLjNh/7pDFLW7T6Kl/tcCjfpQsancB7qCVeZ/D9S7rwpyF5f HzxxsKvgMU05G3AItC6Lw9fGpg7Q6qUSWcyeJevcFJUQ/dc4wOPdOK/59CL3jZjKTzt+Od/0teI Th8/nTpIv+cf4g41RkI5lc/UdPwUI31Gs4zXTL8y5sBEYlUggAb1cqXp2+kVCsWRZ+dklor2Xg1 Pvjp+THidPXyLr690IWReTkWpesKeXXwVRfhAnbhOOzB/FwBsy6S0MpneBmOVcOWF8RFZ1Q6zDG Y9yispcX+IRdUNEdhSmDFCus/t2mhS8t5fyVs4eY19cE5WPXCZEBVrvWxVdPxfyOznd1TAzJPwf KogqlhePlbze0KLVih9abEQAkR5hnfi7mjYEM/OXJCreXfaO+9J4IvwLqhCUSA70rAl5GLFSlPB QPAw+4DqDCXctbRykajQ== X-Google-Smtp-Source: AGHT+IFm4gV7kKat1LdzITQ6wbCjDRLBARxrA83binMW/Nd+eB0NlcEzmwNtCld3J0yzNo5Tt6dsPA== X-Received: by 2002:a05:6000:220e:b0:429:d6fa:da20 with SMTP id ffacd0b85a97d-42ae58829f5mr2936682f8f.25.1762527211868; Fri, 07 Nov 2025 06:53:31 -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 v2 2/5] vvfat: move fat_type check prior to size setup Date: Fri, 7 Nov 2025 15:53:24 +0100 Message-ID: <20251107145327.539481-3-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107145327.539481-1-chigot@adacore.com> References: <20251107145327.539481-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::432; envelope-from=chigot@adacore.com; helo=mail-wr1-x432.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: 1762527257211154101 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 creates 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 fat-size parameter. Side note to mention that s->sectors_per_cluster assignments are removed because they are overidden a few line further. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index de6031db98..d8c8d44f16 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1192,45 +1192,45 @@ 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; - 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; + 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) { + /* 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*/ - if (!s->fat_type) { - s->fat_type =3D 16; - } /* Reserver space for MBR */ if (qemu_opt_get_bool(opts, "partitioned", true)) { 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.43.0 From nobody Fri Nov 14 15:22:08 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=1762527277; cv=none; d=zohomail.com; s=zohoarc; b=KNlwZeTsL21aTViDKLEepia/M9EIW/2yzHRxOtamedgyfW7coBSdZrSwwD3gVbCi1WKxLNk/84pRTHPiRsnt4Fb78e9iTgZNd1Ojzr8yZQf8Ckjlb3yZm2m8TgEFNLVjSA8c0GAJUzfHF7CQB6HZqKXD9Nmy0yF6nUoB+i24uQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762527277; 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=gnnIZZzxrg/0dXW75jADfy3TeL2WXsF9KtnuDUVrdxk=; b=jf0e/jfyhBrTdg6/ILMDedc5lT6U1uysrZ3ZqPbME83KGplRkeWG8HVzY/xxNij81kMPX/ZnYVdTkm6KvmeGuhHH9Y5OhIzjYrqNHH9PW0rU4AKeklCgwYXagL2ovu06UX0HIkyez4UKRGSPenHj8M0FTQ60OkI6YjRYvJKryvs= 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 1762527277299687.8795299248516; Fri, 7 Nov 2025 06:54:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHNqO-0003YP-G8; Fri, 07 Nov 2025 09:53:40 -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 1vHNqL-0003SW-3C for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:37 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vHNqH-0001uY-VR for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:36 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-47109187c32so4081725e9.2 for ; Fri, 07 Nov 2025 06:53:33 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:e453:acd:db85:b66e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63e131sm5922435f8f.20.2025.11.07.06.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1762527212; x=1763132012; 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=gnnIZZzxrg/0dXW75jADfy3TeL2WXsF9KtnuDUVrdxk=; b=MH+2EthPfK/Gpb2I8Ff27CMdwuV1YZqvpBNLeAl4TdvYwcACqFH3VOny3RgN6JnlPc yJGEQhGutXZQc3mIAPK3KwoWCBhloKog/ykD3V9hjBb+r5aHbdgJH8fyHo9un0kdiUD4 3oyA/knSHzgvTPuQGboJqlwQKdGQoNTzhP1ohGIHUd3m6HiO7qwUafqOWN+4VTBl5MTG uAvSEr8peVcb7breAZCioQ1I/JRutl5gfDhso98G7wOHAEvCXmlNZoZLhidKi8C6uxWa Fdzo3ARA7AzaEiqiTfpN9hMW9WZ6M2uCsw9v9CltKmdovIzk7m9sW4ho7DxrGH0Thcd3 VGJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762527212; x=1763132012; 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=gnnIZZzxrg/0dXW75jADfy3TeL2WXsF9KtnuDUVrdxk=; b=QfQ4W7GoEeTqOoAjgs6YGt+V2qYq9BqHoWV4eHVv/JF+/IDdiz3nOM6n3A7tYo7Kqw I95Q6FD62ErYMnj130+zXCqjfkcpGED+7dfon7jqQZYHdgDisVEeUAQK1NnLe+SQFP2B 2cAcH38gCtHbntxZ4yMAzyKJgWLrI0aNx8zHeE6iYo9p4BIL3EyTPJJ53UpYRxJF9w1K bOLk67t0ids3b7l3TLyfKI1VAJC5UIPiHsABIXJX0JKKC4dCLPGxW4Aw5sd3mEvwMS8z 6Su6ulWoTVufniItVRkGWn3z3VAQ145OcryjGqFS9vInFo0ZhuphrtCAJtK+O5YGNNu2 /zyg== X-Gm-Message-State: AOJu0YyC5+UqF5bmPiogds1xUHNm0JOdiKq//jAfH/dyXvwEZOR8B243 SG9qqhjBDAeAQ4pkujlH9wL0b3rohkvZnL5INQgMLsbh6Mw6ZQoGXB91EOubeZVB0A== X-Gm-Gg: ASbGncu0hhRlzr6z41pIC48/+3ysCUrnSbE2CryQGQtt1lw+emrb1no/A3fu28rkbyZ c51ecTk/1jpt7nSVhGzSAYMD1RnfDJ/ZKcx6gh/MsXMNSxJonC8DvEPqgDR6HoAqeSGxgJS/5tq eBMd90mXIi6eGhW02KgWWrv255kLtVJqvpiXhFrzXCiKcCzpxO9Zflgu56FNTDZJ4lMfppCnXAh ZlkHARNOrWWxqIdsymKA2xAUuNnCUQX7rYG2be7dvzQZz3L/edKwboNQScN2i8zS4ysRazaarFf 8s1dW+awbJqVPbxWAvA7rZDwuhUGeu62Wn7OJc6duTQjhG+fGXjNiIqffwW0kyCOIrx371bZbFT +zwxVEU8Yq7X5bpm5SbsgenQDhsv7/QEAacrE9e2U57WH1D8K7nVV0wXlRXEhhmvxtNoeK5p7mz ncptEQkRM= X-Google-Smtp-Source: AGHT+IEpcXszXx+2TG4UQZDOYkXVl7MsuvP3Jc0YE5nIAU7Oqtwr/EfdNU300Y011Frkd5R2N2gT5g== X-Received: by 2002:a05:600c:45c3:b0:477:259c:dbd7 with SMTP id 5b1f17b1804b1-4776bc92cf8mr28094225e9.12.1762527212449; Fri, 07 Nov 2025 06:53:32 -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 v2 3/5] vvfat: add a define for VVFAT_SECTOR_BITS and VVFAT_SECTOR_SIZE Date: Fri, 7 Nov 2025 15:53:25 +0100 Message-ID: <20251107145327.539481-4-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107145327.539481-1-chigot@adacore.com> References: <20251107145327.539481-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::32a; envelope-from=chigot@adacore.com; helo=mail-wm1-x32a.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: 1762527279465154100 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 d8c8d44f16..1c51dfa561 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 */ @@ -1313,7 +1317,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) @@ -1499,21 +1503,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", @@ -1521,19 +1527,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, @@ -1541,10 +1548,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; @@ -1556,12 +1565,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) { @@ -1827,8 +1836,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 /* @@ -1982,8 +1991,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; } @@ -1992,9 +2001,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; } @@ -2172,7 +2181,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); } @@ -2569,7 +2578,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); @@ -2948,7 +2958,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); @@ -3012,14 +3022,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; @@ -3074,7 +3085,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 */ @@ -3100,8 +3113,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; @@ -3127,12 +3140,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) { @@ -3198,7 +3211,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 Fri Nov 14 15:22:08 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=1762527276; cv=none; d=zohomail.com; s=zohoarc; b=FoykjGj8+pHPJiMncWAaQ2eMIeKMYNs+M8v/RgHfNV1mcMUXDRR58ykQ03RxWnSVx5cySmesqI1kq6cIGIrZL1ecIw8MXM/dwVavgTqA6tFPP+Tpmn81O62Zk0gCCNvFJbCQsqWQjlnNk536ebhi3sWDnW8IUDc99+I6T9lm8P4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762527276; 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=NgRV3D7A6AU7eoGPkfrJPq4UVKzASaP5OU2HV5V5XwY=; b=WHJV5XLhj8NVGtH4sAJkhNxcNlS176r++eog/gaast34VEfUrkyRX5BLxcRFXPwnCA+f7dPHrR2xaB9OF0XVt7dHXmXbEPZPHhhoB1bNhKakoDd/5pg9ev69ufvAEGLJihv3VpZttWxaUBQBMfj6YxDwjflNlcjmD8A+tfrNr8g= 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 1762527276684871.7970871609087; Fri, 7 Nov 2025 06:54:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHNqO-0003Z8-U5; Fri, 07 Nov 2025 09:53:40 -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 1vHNqM-0003To-MO for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:39 -0500 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 1vHNqK-0001uk-Aa for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:38 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-429b7eecf7cso616320f8f.0 for ; Fri, 07 Nov 2025 06:53:34 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:e453:acd:db85:b66e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63e131sm5922435f8f.20.2025.11.07.06.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1762527213; x=1763132013; 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=NgRV3D7A6AU7eoGPkfrJPq4UVKzASaP5OU2HV5V5XwY=; b=MzAChgCbhm8idL0k5WIWQHcq52R5Pq4rLEpXJVuYi2ApCI3bQnrPl7nuB7+f+a3ohN xrblK1x30ShjOpy+VMqxdbrx7TENRkvySkCChuq/E8K5Hmyj6DnIgu8NqPNeqk0BuNrT RQjX4tkqiZWAUoZWZReA3DKUo1zf5NhGPPDuHVcenA/Xc4MRMOEovRs0gagbiJceQimV 7uGt2od57Fi45lxR9oDJ6NQ30+VgTX7iHxkZxbHfylXX38IL9p3FLtWNkS2Wav706NBb OGcqW3/NXvG6oPn/5kF+wC4NYTI3yLCJnaaB6BpMcd33jW0lEV2lzb+3T14XELOXPN7s 3CHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762527213; x=1763132013; 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=NgRV3D7A6AU7eoGPkfrJPq4UVKzASaP5OU2HV5V5XwY=; b=Fof99qBelkgN72k8zuBx3KOEo8Yy7NigGE558MHeVWE20FkAISZHt3gSbRVzXByKzU 353aleC+Rf5F8hcRNdIJkEu1qK0r4pxl0C5gWl2BiFdTWco1JBvOiUhYvtJoEZ4DO4Aw mFdnRKP7g4LYQL1n9w3q0rClChe4Rq1/0Gx0jDZqqZ8AH9iYiDfKMe1CZrhnK53IQWMf E17jh2DLjTTLY2bLoVACgDkad+82nIFUW/cMZ5WhZDxBcTlQvcoKegmAWTJWAozEEqsn jq8HkVNdA3wmYoQwrdf1AgR2OpYlWZwuyc0kUT1whv3G+c+pco4CjoKrEuJuytV1hgib Pk0Q== X-Gm-Message-State: AOJu0YyC1Likl2vDH78Z0a3hqdw46hAtICunbNHc/X3MUyeNVtbBjoM2 O0kqEg8AVkD7ksglIsSw4/7LJzPVEsrFeXeiwY4jpS9ZFtPBh8xRDSi1REwlP594mw== X-Gm-Gg: ASbGncuJ+XMpp20TuaRTfkF+zb984p7v5lOYzE9+oeCx886+c9uaUD9mj7wes95S25N 2IyXDyZSOJvcw2jzoFQOWf4TSLug9Uo3VcpDq6gNcrFnyC/htNEJ+/w7OD2hhOH3x9oXjkFFYG1 xu6PQLajKfuKrv/FYZ9a1SoDzY6c7Lu4yX2c7jvI8vx1j7mCaCk0C0ltk29lWOL62jxt295W3pD IM1ioVLS23KiLSaRC9pftFQ+UcPAkQCyWKlcmdbJaVkz9QqXSQCJxV/LuLWRyOESBD1NhTH13Bp GMnt4ybHr+xQufe/t4yzVtXGyRMzdYBT1y2PL/6fG+8I/9wJR8M9U8RWM4MQBZ4dHvfv8o5S0ry ldl2GKS1U3vvOKsAzajQdMqtwMxL5l24nUReGfUpHHe4s7AcgEsGHK9D5OK3lM8SC+bBVSKuFWD 1QMZFrWBU= X-Google-Smtp-Source: AGHT+IE9lrmPZkbZj+aG13ojPgDeArQzWU0HveRwgo8YI6t+ocODNiDJQTZqUO9jvYS6iotXoOQQ4w== X-Received: by 2002:a5d:5f83:0:b0:429:c6ba:d94e with SMTP id ffacd0b85a97d-42b26f689c6mr2243709f8f.12.1762527213269; Fri, 07 Nov 2025 06:53:33 -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 v2 4/5] vvfat: move size parameters within driver structure Date: Fri, 7 Nov 2025 15:53:26 +0100 Message-ID: <20251107145327.539481-5-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107145327.539481-1-chigot@adacore.com> References: <20251107145327.539481-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: 1762527278986158500 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 1c51dfa561..b0e591e35e 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 @@ -1154,7 +1156,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; @@ -1221,18 +1222,18 @@ 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 { /* Reserver space for MBR */ if (qemu_opt_get_bool(opts, "partitioned", true)) { 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 @@ -1249,10 +1250,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)) { @@ -1273,7 +1277,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; } @@ -1294,7 +1298,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 Fri Nov 14 15:22:08 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=1762527267; cv=none; d=zohomail.com; s=zohoarc; b=bquTyNOSc/R+lKs8YbtKcLhznkE+E3TM0MmUjcvUGS9BiXCMnREC2CaDHZVEBTND0YvibrEA+T/UyRUU4IBoJCy9KeFOLdQQfFHsxsjrthNnBaLhwsPDHh4yCMxXwMKowp5q66mCxeeSnUt3hJwBgR7EZa8MQaVX8mko3kUJPfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762527267; 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=BThCjqaenmyeD9EsuFRpmtd4rv5WpUA+nY9VQioN73Y=; b=PZ6eeYnSsDbBw4jSB0eMPUq6MH2GhShg7ny9HXuwyERmSzMmgQd77es49hsbUnheOy16ZWG2LUHoR2J/PIh6x3dn6RQTNuXIyqIpaxO8kxIz9UDYMb68Pfx+8Byv6VS8FN+ar7vzeJ3ssq7xbP8D7KP5fOl71/YVH8HKBG+0NJ4= 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 176252726790444.22881574147766; Fri, 7 Nov 2025 06:54:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHNqU-0003hp-Jr; Fri, 07 Nov 2025 09:53:46 -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 1vHNqM-0003Tr-Mq for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:39 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vHNqK-0001v1-BO for qemu-devel@nongnu.org; Fri, 07 Nov 2025 09:53:38 -0500 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3ed20bdfdffso795900f8f.2 for ; Fri, 07 Nov 2025 06:53:35 -0800 (PST) Received: from chigot-Dell.home ([2a01:cb15:80db:7c00:e453:acd:db85:b66e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63e131sm5922435f8f.20.2025.11.07.06.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1762527214; x=1763132014; 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=BThCjqaenmyeD9EsuFRpmtd4rv5WpUA+nY9VQioN73Y=; b=G+szwIjuE5Ep4o8wwdujWBNPCnRi/m7iS7zMCi+BYD+HkuAIPmwZmpcYZ0nky+kQJ1 +GnlQYKQ1m8KttJbwX/+/01V4ewuFDnQvq8bf/eMECJUpHB6GJid1qAvTLZ9chvSNM3J lTSW7VoOj6aLzGUbQE34PMlbP2NcWs1fjF6AYPZSZoOAmlQPpb6Md4YzCT0iJtQoiMe+ /6r9h3t3326FUyRssd+sUKE6IJCICm1obfxVs/rha3WTQlw7w0S5aD/dLazDTLr3EFAq e22WOlTyufWNkl00DbEtSBMXUbStDaiaQ35lDOd715HsNDnLzurNrEfwiYxIk77b+1Vs F42w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762527214; x=1763132014; 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=BThCjqaenmyeD9EsuFRpmtd4rv5WpUA+nY9VQioN73Y=; b=UqFDFUcRVfRh2W9+4rJv2dDnGjFLBBn6I0TaKfXCslt7eWkg30dF8M3m7m3rGjRkXH +2dO+otViyhLxx97Prm/LXgl3d9EVD6ZBBXgDtzgJxgpHvxV7pR07esPEc54NR3EH+kz xGkWv3KRbwEznCu4NRAh36v4qOCNB2l1VGQgYomiHWRpp15McjFX56A76+XJT7VDvvCT hgxYw3Caol8lD0MpNQ+CBPzhmW41Y3VJWLjILj2lCtOx1mFIBB2oUPvWcv1UPsgOAbp2 BNE52rlWc1q05R+InLFr3g49mBFa2I6kBkr9ABfdAE5EirUhcHEVQz+4L8C855sQhat1 VpfQ== X-Gm-Message-State: AOJu0YwF+wG6UsKbaTc9ZgSa+JIR9PbJeO+HxLVoboFZnHVAyPyCFgvg H9ZZN6rPsJc5vsTihbbbXcWDc9/4JMma/CxOH0XPt5sGc92UPi4kZFBf+y3koAzJaQ== X-Gm-Gg: ASbGncvIAMBoMeBnMz98tqMydzYYjfklfMc/Wmwqs+tufu2Yo4FSux4X8fChiN0nFqF XyxPFPGuJWW99+0DDvO+RlOA/NsoVXU91URVBSiW/OaxyUjOaKYDGwjP5EfNSsDzaqir26vAXsu vFZawFC8SVQLNMu9q8puN0HP+HP/kNLY/vtQTwaWOiRQ4LMxPOip5gylcK1UUpfnbRq31pNqGd2 tqjSIB3EabhZog5u6E6trkWrEP7OUnp9Q6woApr9zhBT3AdLAdC4LxPbjYXAw+JGPpVihYEq186 UyYIhe0YRDTUfNP8nMP+5/JM2tPQgMauJQEyqYZaEPzPk0sZ82NW+IJ/JTg5YjNF7mDHMwTEv+J tM8HIMh9MSVfvkWhmeAMx/9hUfkjJ/gxQWKae2gMABzV8g8jzXRZu3x3+QtQ89J7VzxybXwERLQ OGtM8WkR0= X-Google-Smtp-Source: AGHT+IH53mykz/MiKBT8Ux/WHXoRE4h9QmmUOIyNK49LI8eTL0TCywmhx663ZwWjdoiXOIB9Ez/9Fw== X-Received: by 2002:a05:6000:2209:b0:429:f01d:dd92 with SMTP id ffacd0b85a97d-42ae5af4989mr2784365f8f.59.1762527213878; Fri, 07 Nov 2025 06:53:33 -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 v2 5/5] vvfat: add support for "fat-size" options Date: Fri, 7 Nov 2025 15:53:27 +0100 Message-ID: <20251107145327.539481-6-chigot@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107145327.539481-1-chigot@adacore.com> References: <20251107145327.539481-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::435; envelope-from=chigot@adacore.com; helo=mail-wr1-x435.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: 1762527271400154100 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. Signed-off-by: Cl=C3=A9ment Chigot --- block/vvfat.c | 169 ++++++++++++++++++++++++++++++++++++++----- qapi/block-core.json | 8 +- 2 files changed, 158 insertions(+), 19 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index b0e591e35e..96f5062939 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1095,6 +1095,11 @@ static QemuOptsList runtime_opts =3D { .def_value_str =3D "true", .help =3D "Do not add a Master Boot Record on this disk", }, + { + .name =3D "fat-size", + .type =3D QEMU_OPT_SIZE, + .help =3D "Virtual disk size" + }, { /* end of list */ } }, }; @@ -1152,10 +1157,150 @@ static void vvfat_parse_filename(const char *filen= ame, QDict *options, qdict_put_bool(options, "partitioned", partitioned); } =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; const char *dirname, *label; QemuOpts *opts; @@ -1182,6 +1327,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, "fat-size", 0); =20 memset(s->volume_label, ' ', sizeof(s->volume_label)); label =3D qemu_opt_get(opts, "label"); @@ -1219,29 +1365,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) { - /* 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 { - /* Reserver space for MBR */ - if (qemu_opt_get_bool(opts, "partitioned", true)) { - 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, "partitioned", true)) { + 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; @@ -3280,6 +3412,7 @@ static const char *const vvfat_strong_runtime_opts[] = =3D { "label", "rw", "partitioned", + "fat-size", =20 NULL }; diff --git a/qapi/block-core.json b/qapi/block-core.json index 8a479ba090..0bcb360320 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3478,11 +3478,17 @@ # (default: true) # (since 10.2) # +# @fat-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', + 'fat-size': 'int' } } =20 ## # @BlockdevOptionsGenericFormat: --=20 2.43.0