From patchwork Sun May 16 10:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1478981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::238; helo=mail-lj1-x238.google.com; envelope-from=swupdate+bncbd2zdgn6sekrbi65qocqmgqerjmgefy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=oXPyyLhM; dkim-atps=neutral Received: from mail-lj1-x238.google.com (mail-lj1-x238.google.com [IPv6:2a00:1450:4864:20::238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FjdG54np7z9sVt for ; Sun, 16 May 2021 20:06:35 +1000 (AEST) Received: by mail-lj1-x238.google.com with SMTP id b44-20020a05651c0b2cb02900ec3242ba00sf1846868ljr.17 for ; Sun, 16 May 2021 03:06:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1621159588; cv=pass; d=google.com; s=arc-20160816; b=UHuWN1ADIY72yLKq2OKZPQc4yO+vs8STCTWin1uRZ51DrwOggGS49sYS+izuSKYKA6 a7iGg14I1bbDU66ioW6C/yqxNio83xDDcWwZghEgdfGLt0yD5tzNiXUkAzXpQC8jGJFo VVCe91PmTV+IsNpd/DrbVIx2DLGpyJPZMCHOw5JVTftXeP62B9tWhTTRF6nxkIfUt3mI 5xmvqYzoa5wYUTkBL+MK1N7WRNSDlvKiaiHmnbC0iUo4Nx+9DH1HsfefE9E4MpYi2lI6 JOOCVVsFHr4ENLe3V5Zx0Xynubhykt2c86+nWuvttdeeQvk44Ck48APXABdxPt8b2uCA UgbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=U1dVlh034YUjacCHiHioLsW3MVUPg3A4JUMlsnPASwM=; b=Dk9VDpIse2HF8Tp/DwTQvZeFIc2TS8N+g1ld/VCWLQusTMVwcOrX1VzgkjMTlsfx7I DItkE3WDP0XzeQ1030WriARWRMN3WSYQoqk9/3e8PQJnmnkfuMh5tPzQT7/TLvoD2Mct 0M/26QdFFKVbmsAG59lPfbHu/8afRb4ba4t5df0DRyIRiBOR/WL/zbwvRxZBc2WsbO/d stbK2PYBjgPt1IJsHaBNJcb2k2xEBUyWVcibKEWa4i8OMXP19+RJ4UgzP3Cgh2jPTGgt 5VzQ4CQdZIR+2dLk6RM+/VK1S+JLIFxuSo3f1L5i27iNRl1MA3HFTwLeCGoiJ8inbi05 T7Xw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of stefano.babic@babic.homelinux.org) smtp.mailfrom=stefano.babic@babic.homelinux.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=U1dVlh034YUjacCHiHioLsW3MVUPg3A4JUMlsnPASwM=; b=oXPyyLhMJJx8C8oqQeY6Ec4MubHCiflYHj+YygU8Nfkb8RnMJa0dbrDZns9Osrm7Z7 ZOcYd9bPYeBvMv3E3Lf+uCreUGitm0rlCasg5wwcsoRONkSFY2Fy195/9/0OiUaVvacN AwuSilejaOPqbcVuV3J6NY+3YX5/Qpxb+3k/n30WnACr1weoTCG2dYfZ36GGZQmIE0Jv 1RxOi31b2xF2l0xkujWvDrUvd0hvq0ubzN913Po3r+LfaqLWK11F9mstLvugBL8xRoKK UKLI8JgbbJaAHjtkOqsGvFZqB2q+NHqnZCNamkSvTazkULlCMDlfriGYnFTsBPCwKlpt sDlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=U1dVlh034YUjacCHiHioLsW3MVUPg3A4JUMlsnPASwM=; b=eOFTeK/ytu/NuxvAWa18bpIYx54EJwMHS7P87TFgFJSoU/40MsnV73wkvCULcojwbM m3mR9CoWTu9w1IZqeXEq8mgEMz6F9rOlDImhCZRjr03knQoqGJkQ51rAwZU2ZO3Ljdpy ZUK7qY/59sPRy2GgBUPWiEZB+t16dJBFfE8Zk6MglBzJH6a86e3j3TLz6Ao/7Z4wHy6X fq2le4C6w4P+F9cOwL2hRqojV59cI9wGEsGVUq3UIMzCy6tfslYMb6sMSWErTRnXBJje P6TJ0ryExXVAf3+M9DrtNUrEnDGL6vzvF06OwLU4IR66MknGoKXpIMtoT3eogHrQtdH6 NiGw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531KGVw/vDUI5s560h/VhhQBosBH+zxAULSHUoPxwFdnacIR6BKK yDTKHXo69pXrZE/GUC+GTQ0= X-Google-Smtp-Source: ABdhPJz7CdItZ4rURD9cHH63WPYuxOCcrFCf/t1qiF/yZKgcxwgdfJc4ahjaPBdhBNi5gbXq13SYJQ== X-Received: by 2002:ac2:592a:: with SMTP id v10mr1975714lfi.400.1621159588459; Sun, 16 May 2021 03:06:28 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:9806:: with SMTP id a6ls2341535ljj.10.gmail; Sun, 16 May 2021 03:06:27 -0700 (PDT) X-Received: by 2002:a2e:a792:: with SMTP id c18mr27173219ljf.179.1621159587249; Sun, 16 May 2021 03:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621159587; cv=none; d=google.com; s=arc-20160816; b=mgTY9l+IHoo0U6zDVGVzmMGDF5/LZCKvxsZltWDyJX4fRXSO0Gf5lMcbytMOs9zni0 lnOV67FnBGdySH1G1714KwMqPshWBEnYuRuis/BNchShFJ3KO1kCde/fG+zLSD4dNUcD VG4MzCoG2A03sQeXa8tTCc36oHHqLZ0WHYthWNFjluuK8FgRnh9LSJ5weOuBZuagx50C x3Z8zGkj06fmVxOPUy5bxSSN8tmOqvekJDTwH+y3s5TTUJO2oV/bO61Jgiebz4HX05pP 1x3Xn6BkvgiGNxRsAQzwUCdS4uGB52bLKjznQioGlHNlPbLgc6pwGualKfV6bqfeFN5k TN9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=rGtX/6Rhhehdg2JassO5PBbrrL6Y+29EJvz7oue4DV4=; b=hD5yExDNNmwYIuRXne8WyLBA1b+dIw+ofHvr1AUobBbjO5+4J8DFJu0NRakNThZZ/d PJa9WWKVNDcM7OTLpo1igVnYUMGwNWgbUij2lMFaA/JQNpyZK3iSLKmZmYJRCYTkOWam 52skkC+d5d51OXpUuq9iuYGmdQ7srWic+amq+wQ9qYhqzxAEcPVYiOJJ+yebAXitplQ7 ybGBh/9w9NkxCZ3+h0ip+uXcNJ3G+zf7cJjzRpiq2KtuaWKMklTyR6GTkNizeFiByQTC UJdz76sXnA3NVjo1QiiKJTN6TFK2mz2tnkIQOj/lRLovgMZV2AHBsvQs2AMqCsUB67+V YYtQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of stefano.babic@babic.homelinux.org) smtp.mailfrom=stefano.babic@babic.homelinux.org Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id w26si414231ljw.8.2021.05.16.03.06.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 May 2021 03:06:26 -0700 (PDT) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of stefano.babic@babic.homelinux.org) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4FjdFt1ndCz1sHJP; Sun, 16 May 2021 12:06:26 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4FjdFt1QnMz1qsb3; Sun, 16 May 2021 12:06:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id r6x2lF3RhjiJ; Sun, 16 May 2021 12:06:25 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Sun, 16 May 2021 12:06:24 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id A82484540D4F; Sun, 16 May 2021 12:06:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 928FU0-DjPMW; Sun, 16 May 2021 12:06:20 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id B4BD645409A2; Sun, 16 May 2021 12:06:20 +0200 (CEST) From: stefano.babic@babic.homelinux.org To: swupdate@googlegroups.com Cc: james.hilliard1@gmail.com, Stefano Babic Subject: [swupdate] [PATCH] diskpart: fix comparison for automatically size partitions Date: Sun, 16 May 2021 12:06:17 +0200 Message-Id: <20210516100617.37101-1-stefano.babic@babic.homelinux.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: stefano.babic@babic.homelinux.org X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of stefano.babic@babic.homelinux.org) smtp.mailfrom=stefano.babic@babic.homelinux.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , From: Stefano Babic The comparison does not work for automatically sized partitions (last partition on the disk). Size is not defined in sw-descritpion and the test forces to write the table. Check if size is not set and that there is no free space on the disk and skip size comparison. Signed-off-by: Stefano Babic Reported-by: James Hilliard --- handlers/diskpart_handler.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c index b10ffc6..7842806 100644 --- a/handlers/diskpart_handler.c +++ b/handlers/diskpart_handler.c @@ -131,10 +131,24 @@ static int diskpart_set_partition(struct fdisk_partition *pa, return ret; } +static bool is_disk_full(struct fdisk_context *cxt) +{ + struct fdisk_table *tb = NULL; + int ret; + + ret = fdisk_get_freespaces(cxt, &tb); + if (ret) + fdisk_unref_table(tb); + return (ret == 0); +} + /* * Return true if partition differs */ -static bool diskpart_partition_cmp(const char *lbtype, struct fdisk_partition *firstpa, struct fdisk_partition *secondpa) +static bool diskpart_partition_cmp(const char *lbtype, + struct fdisk_partition *firstpa, + struct fdisk_partition *secondpa, + bool skipsize) { if (!firstpa || !secondpa) return true; @@ -150,7 +164,7 @@ static bool diskpart_partition_cmp(const char *lbtype, struct fdisk_partition *f (!strcmp(lbtype, "dos") && fdisk_parttype_get_code(fdisk_partition_get_type(firstpa)) != fdisk_parttype_get_code(fdisk_partition_get_type(secondpa))) || - fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa))) { + (!skipsize && fdisk_partition_get_size(firstpa) != fdisk_partition_get_size(secondpa)))) { TRACE("Partition differ : %s(%llu) <--> %s(%llu)", fdisk_partition_get_name (firstpa) ? fdisk_partition_get_name(firstpa) : "", (long long unsigned)fdisk_partition_get_size(firstpa), @@ -388,14 +402,27 @@ static int diskpart(struct img_type *img, while (i < numpartondisk && !createtable) { newpa=NULL; pa = NULL; + size_t unrefsize = 0; if (fdisk_table_next_partition (tb, itr, &newpa) || fdisk_table_next_partition (oldtb, olditr, &pa)) { TRACE("Partition not found, something went wrong %lu !", i); ret = -EFAULT; goto handler_exit; } - if (diskpart_partition_cmp(lbtype, pa, newpa)) { + if (diskpart_partition_cmp(lbtype, pa, newpa, false)) { createtable = true; + /* + * if this is the last partition, size can be set + * to take all the remaining on the disk, then checks + * that disk is full and skip size from comparison + */ + if ((i == (numpartondisk -1)) && + (fdisk_partition_get_size(newpa) == LIBFDISK_INIT_UNDEF(unrefsize)) && + (is_disk_full(cxt))) { + TRACE("Disk full partitioned, do not check size for last part"); + createtable = diskpart_partition_cmp(lbtype, pa, newpa, true); + } else + createtable = true; } fdisk_unref_partition(newpa);