From nobody Sun Apr 12 07:20:19 2026 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1771237892; cv=none; d=zohomail.com; s=zohoarc; b=JRZhxQ1e3NdGu0Y7X/B5bBeCiHamodjAz+WpKQa2vso1TMGFzv49mwFBY7KQpqb62/6uXXrw5Rqm/LLWElsbRirlD9a/nxBD8fqMT2jb5+q7EyqZUc82gAdDtRnf4eJylFuj5ju11rZDMJ7KS7VyZEpdlSulPwBppVQzO8SmPCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771237892; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=9y4jIW3yOBt9OHzqVap3xId+tC7KWpl0iJxMP328cPk=; b=QDnEXVdGCu90nY++Z3/MW8CZPDcnUb2cYFo6uZcUtl6cg6qiYIspoXf4a0OUfNC4zp500GcSu/LnmxzWSqcGPGaJIwCzb7GRbkgOu+vl/kcTrXUyf1LhRRaaKBhy1SGmDq0uw3hgRGaSemI2Wly+vabDjTsTD2bQ6LiDt1Gw/4I= 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 1771237892838445.73699632226305; Mon, 16 Feb 2026 02:31:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vrvrs-0005xY-Bj; Mon, 16 Feb 2026 05:30:16 -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 1vrvrl-0005we-EH for qemu-devel@nongnu.org; Mon, 16 Feb 2026 05:30:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vrvri-0006m7-Od for qemu-devel@nongnu.org; Mon, 16 Feb 2026 05:30:08 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-AfG6aiP6NfiKNsxDsSjSnw-1; Mon, 16 Feb 2026 05:29:59 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E8F8A180025A; Mon, 16 Feb 2026 10:29:58 +0000 (UTC) Received: from srv1.redhat.com (unknown [10.44.32.156]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6E551800666; Mon, 16 Feb 2026 10:29:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771237803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9y4jIW3yOBt9OHzqVap3xId+tC7KWpl0iJxMP328cPk=; b=XL7uEidiWzBkEtA9JMprH0cejeT4pLwmP95DonogJVl8DhNIQYnByy6wWL5aWk+K9sq1zG c22/vY9qMDCrLnlu+PfPMSIWhzUtEWxJ60wgnZ18R+kPSh+saQDb32Iyfs8d4GTYEoyjaf wtzxlIv2GCQMnjb5XcBSycxAS+XNEn4= X-MC-Unique: AfG6aiP6NfiKNsxDsSjSnw-1 X-Mimecast-MFC-AGG-ID: AfG6aiP6NfiKNsxDsSjSnw_1771237799 From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , Richard Henderson Subject: [PULL 2/5] util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c Date: Mon, 16 Feb 2026 12:29:48 +0200 Message-ID: <20260216102951.150381-3-kkostiuk@redhat.com> In-Reply-To: <20260216102951.150381-1-kkostiuk@redhat.com> References: <20260216102951.150381-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1771237894222154100 From: Nguyen Dinh Phi qemu_ftruncate64() is a general-purpose utility function that may be used outside of the block layer. Move it to util/oslib-win32.c where other Windows-specific utility functions reside. Signed-off-by: Nguyen Dinh Phi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Pierrick Bouvier Link: https://lore.kernel.org/qemu-devel/20251218085446.462827-3-phind.uet@= gmail.com Signed-off-by: Kostiantyn Kostiuk --- block/file-win32.c | 32 -------------------------------- util/oslib-win32.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/block/file-win32.c b/block/file-win32.c index af9aea631c..8a44853389 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -170,38 +170,6 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, H= ANDLE hfile, return thread_pool_submit_aio(aio_worker, acb, cb, opaque); } =20 -int qemu_ftruncate64(int fd, int64_t length) -{ - LARGE_INTEGER li; - DWORD dw; - LONG high; - HANDLE h; - BOOL res; - - if ((GetVersion() & 0x80000000UL) && (length >> 32) !=3D 0) - return -1; - - h =3D (HANDLE)_get_osfhandle(fd); - - /* get current position, ftruncate do not change position */ - li.HighPart =3D 0; - li.LowPart =3D SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT); - if (li.LowPart =3D=3D INVALID_SET_FILE_POINTER && GetLastError() !=3D = NO_ERROR) { - return -1; - } - - high =3D length >> 32; - dw =3D SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN); - if (dw =3D=3D INVALID_SET_FILE_POINTER && GetLastError() !=3D NO_ERROR= ) { - return -1; - } - res =3D SetEndOfFile(h); - - /* back to old position */ - SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN); - return res ? 0 : -1; -} - static int set_sparse(int fd) { DWORD returned; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 839b8a4170..766c602172 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -899,3 +899,37 @@ int qemu_shm_alloc(size_t size, Error **errp) error_setg(errp, "Shared memory is not supported."); return -1; } + +int qemu_ftruncate64(int fd, int64_t length) +{ + LARGE_INTEGER li; + DWORD dw; + LONG high; + HANDLE h; + BOOL res; + + if ((GetVersion()&0x80000000UL) && (length >> 32) !=3D 0) { + return -1; + } + + h =3D (HANDLE)_get_osfhandle(fd); + + /* get current position, ftruncate do not change position */ + li.HighPart =3D 0; + li.LowPart =3D SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT); + if (li.LowPart =3D=3D INVALID_SET_FILE_POINTER && GetLastError() !=3D = NO_ERROR) { + return -1; + } + + high =3D length >> 32; + dw =3D SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN); + if (dw =3D=3D INVALID_SET_FILE_POINTER && GetLastError() !=3D NO_ERROR= ) { + return -1; + } + res =3D SetEndOfFile(h); + + /* back to old position */ + SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN); + return res ? 0 : -1; +} + --=20 2.52.0