From nobody Thu Nov 13 21:52:17 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582823129; cv=none; d=zohomail.com; s=zohoarc; b=QHqUjFbarUAueKJ37bxyz0ra5AH2OTrY84Xyq+vaNHQF4mfG0pOEFNUIGtVKGm1Fx2ldzKMvNWxcZOenDRc2BUDIbZFRKUu8qZCYKg4LF3SWPZZB5B5F2a63wroNYkiubwA95/xau7Inw26Owd9Qx4zF39tNv/SFHDeOzAUYrIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582823129; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fNNuMeUDHOCcalcEBI6sJ90tiH3NcqHgqyX/YOhqAdw=; b=Y/XKz1fJcYYZCias9uydktHagc+Zu6JPiX+SXlLzIstdcNFOlckbBWtm51LIBa+XRXLFLcDLUQC+RfxHikGj8vLFrSUAUdI6z/UYeVTKvxyK2w/YzNUUoSlIxCFICYDxqT2O+yprc74APepSw8KX6JNKppSeQpght6fdkoYgalo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582823129485686.1185985004986; Thu, 27 Feb 2020 09:05:29 -0800 (PST) Received: from localhost ([::1]:35062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MbI-0005sv-Ao for importer@patchew.org; Thu, 27 Feb 2020 12:05:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47207) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MYw-0001mT-Si for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7MYv-0000TQ-RE for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:02 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54115 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7MYv-0000TG-LC for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-guzpLXHePfOHKh2fpUTGew-1; Thu, 27 Feb 2020 12:02:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C332185EE7B; Thu, 27 Feb 2020 17:02:57 +0000 (UTC) Received: from localhost (unknown [10.36.118.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6546C60C18; Thu, 27 Feb 2020 17:02:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582822981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fNNuMeUDHOCcalcEBI6sJ90tiH3NcqHgqyX/YOhqAdw=; b=DPQo74DZvW+RV6NMG55h30CLmUAFCpPJ5yuZBFl15qz+OR+QDiiUUffcIifie1hsctdn0v bNP5UNctJTMaOvzxVM0eDDguPjgBOju72mA4dSEuYuPXiIWWYkxOYJMyK6um3wIAFczrUv kryqWP1E/16IUrgsJvNX2DFyTOZm+DY= X-MC-Unique: guzpLXHePfOHKh2fpUTGew-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 2/3] iotests: Add poke_file_[bl]e functions Date: Thu, 27 Feb 2020 18:02:50 +0100 Message-Id: <20200227170251.86113-3-mreitz@redhat.com> In-Reply-To: <20200227170251.86113-1-mreitz@redhat.com> References: <20200227170251.86113-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Similarly to peek_file_[bl]e, we may want to write binary integers into a file. Currently, this often means messing around with poke_file and raw binary strings. I hope these functions make it a bit more comfortable. Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 4c246c0450..604f837668 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -53,6 +53,43 @@ poke_file() printf "$3" | dd "of=3D$1" bs=3D1 "seek=3D$2" conv=3Dnotrunc &>/dev/nu= ll } =20 +# poke_file_le 'test.img' 512 2 65534 +poke_file_le() +{ + local img=3D$1 ofs=3D$2 len=3D$3 val=3D$4 str=3D'' + + for i in $(seq 0 $((len - 1))); do + byte=3D$((val & 0xff)) + if [ $byte !=3D 0 ]; then + chr=3D"$(printf "\x$(printf %x $byte)")" + else + chr=3D"\0" + fi + str+=3D"$chr" + val=3D$((val >> 8)) + done + + poke_file "$img" "$ofs" "$str" +} + +# poke_file_be 'test.img' 512 2 65279 +poke_file_be() +{ + local img=3D$1 ofs=3D$2 len=3D$3 val=3D$4 str=3D'' + + for i in $(seq 0 $((len - 1))); do + byte=3D$(((val >> ((len - 1 - i) * 8)) & 0xff)) + if [ $byte !=3D 0 ]; then + chr=3D"$(printf "\x$(printf %x $byte)")" + else + chr=3D"\0" + fi + str+=3D$chr + done + + poke_file "$img" "$ofs" "$str" +} + # peek_file_le 'test.img' 512 2 =3D> 65534 peek_file_le() { --=20 2.24.1