From patchwork Tue Jun 22 01:52:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 1495413 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=2607:f8b0:4864:20::c37; helo=mail-oo1-xc37.google.com; envelope-from=swupdate+bncbcl4hcw73qcbbzeeywdamgqetizwqiy@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=BIU9LfHg; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CN/8J6Tz; dkim-atps=neutral Received: from mail-oo1-xc37.google.com (mail-oo1-xc37.google.com [IPv6:2607:f8b0:4864:20::c37]) (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 4G88Y74Crsz9sW7 for ; Tue, 22 Jun 2021 11:52:41 +1000 (AEST) Received: by mail-oo1-xc37.google.com with SMTP id r4-20020a4ab5040000b02902446eb55473sf10301511ooo.20 for ; Mon, 21 Jun 2021 18:52:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624326757; cv=pass; d=google.com; s=arc-20160816; b=zua+HQzxpATOVqYz8W3/nZKAS8okSLfvj0Z3PdVRS7XGLbYYCBSOM7/gQxOZY7sEE8 dSnOMhQpzbIb8hPeQVocVbAbPEKX0I5pc9FR22y1hxR3T5ZHvLG/p8Rn8RTA107PQftp tTq8m2icoRxz0tNMIyypPt96Z1noToCj74d5uZOBBQ9Ml3KJwOiC2s/GlLtWfXCrbpjx bGVweMl2Po/4nzv7JQbneoqoXZSjgL+ZBGdWVo/uAVGP6wQKOUvN0KSoZVlMwX4kuc6a s1ffiDaiV904CrqYMlYPTufM3f0cTUCg7BXfc8yjktbof2lCK16PbdKPzgSYgk+TMoEX fwXA== 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:dkim-signature; bh=awekeur+AX5iTBpzW5XhJx4ZyrHH76fRDCkdDxVAOV0=; b=wm2sd9xLKe3C+B3JIk8334VkpashRHbQYgSbAlsg8ncS2crXy9pIvXAlzqscTZkWFv z/0TbS1ws/Xu4qN1uTZxUZu3QQs5Gl7caYCc5M+HIrcF60MovHP5yQxaI3jF2nwtCOUX kzByZ18hACHNETABraKCjFkmYbPouzQS0cybZVX0kJofylqS7TttR0lcF9Ifqt9UZz1M LuBXXtyp1k/EBP7UpYKBlHQ1VdYOSI6zgJsUAwZaMjqZQvy/Nx2qYQwuAhpNKpXk4chI OPw5t/sxJCCNumnZdTxFrD9JiDBvPv1zx80RSaefk3At199vTqPAzd2NML+b/xmu0i0T eILQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tsIy3s1g; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::229 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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=awekeur+AX5iTBpzW5XhJx4ZyrHH76fRDCkdDxVAOV0=; b=BIU9LfHgW87d3eB4pNe5R6PAhblZcrIjdXyycRiFE5takuqW1mP+HAl25HNN1LHXEy mZ7kVtBPnaZjpopc7MUi+WqMtQAU3JHTItBAWnE5sa/SWOZUzxz6DT55ePyjFgPtVK6J sNCz83oPQhuFXhuKrAkN4UQib5KDAMXjY6T7fRdqbD4NV4zSasCERTUpLZ+oxBVel0W9 BSFkBJaZFY7W3evL74rRBQEIQ36tTSOb9KnaX/od4TgB+XqklvBgBDeK5KC7455+8TnR 0IH8YCh1V2bsz2+aVBZwVICH6BaLAmVATL419NwqEcIvEKlRCfhwDqCVXsLjIt3sEJo+ BLKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=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=awekeur+AX5iTBpzW5XhJx4ZyrHH76fRDCkdDxVAOV0=; b=CN/8J6TzH4KGnksJW3XSMYUyiVI6cm4ynfUbhvmhiCNErEaZ88VQW+IzjFuPdI+sgA ivKT07yLOjPQquY5L6bHgAPVdDN51W0h0ttcuWypSE9eVKNRJXkYwU7f4ybPxQg/P2bG dg2QRLewqJqetZi3+7h9/fLMySESkWhmL7QegOcUm2ISlS8gIa6kyZzhTkZ52hCyoogY N7ZRGu9NL8D59xhdB/sfK9+8WxtRpoYzsiTkjK6Spqx/mZ/Kr0kk1h2wDVg6OpgoqbIP B2ATtG57/WjGT0PsIf7xXudzisKIkbzRGhtf+nYiBHyp36ipxr68C98BGBrcAhrXohN6 FkVA== 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=awekeur+AX5iTBpzW5XhJx4ZyrHH76fRDCkdDxVAOV0=; b=lADvo3FEf1UoM63KgyfksPf+CfoIw3hJFioVUySByhNZYXLYlINpvO18kxTF2iZZm1 +xgnLag7Uu6DrW5Q+RTsOR1RRsFgUj0yt5fvAsancUPXuvIiZeewy7KTkNZT9W6fPaLY Sa/23lBMR+cQizwb6sHPuMmqaeiWHBBMLBxckwq7JMWiDxXpme45Aih7JbsX5uvXaa93 qQ5bcv7pQkfqzSa2fEiphc8CncwcAr3z3XYZp9zn8cTLQWdR77hABCkMaGUmvIixnrN4 43XhfFwRtQ85tFFgGjKDxsW2ZyHNdkr97xSXYEBdnkNIewksIrAPmVFZTrRps6Q2Z0P2 4CPQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531sIddQpK/Uy0x4JoAjhFKdQoOk+vo+BBg1x7lnl4wH878ltl/o iSMjW3sxiUSQCZrPACfQakc= X-Google-Smtp-Source: ABdhPJyjn7UBByZu5S+D4wzAbNI7aE3tHSM4Q+6FOpg3x4rszikaYxIj65GTm7gnLv8hu/cmsQg3uw== X-Received: by 2002:a54:4706:: with SMTP id k6mr1216310oik.61.1624326756847; Mon, 21 Jun 2021 18:52:36 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6830:1310:: with SMTP id p16ls7053535otq.10.gmail; Mon, 21 Jun 2021 18:52:36 -0700 (PDT) X-Received: by 2002:a9d:2f61:: with SMTP id h88mr906913otb.190.1624326756403; Mon, 21 Jun 2021 18:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624326756; cv=none; d=google.com; s=arc-20160816; b=0ACi9FzzUAsXu/RK3v4uCM7nRIAOG4Mfw5EiOjKvFcRRO3VWQO6vX5nnNyN1swWd+J qNt7U/wjJ3L2fJZc78DRwmdEgHkofzKLVjkzhIevdfJS8pbP/MN0EBs/nHt0+/0R26ED K3fq2mx/DGrsMrrTnitgPvkoYt768R4OJsDlfWvIUJG39YEzGOP/tJD2O2nmmKxoeIoP k1oKdgZNR22Y7UtduSfmVrc6fcvrtttQxLIf4x/DImOBMi18erfu/Row3OrTqSzzrN6/ V9Ty9iAsdBoNXAuavn6unsukC0DFIbXEz+Nxcfwr8vf2cuvZGo8wWRQeVW9oFgxdvJVO 98vg== 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:dkim-signature; bh=o8Bdfhg/PHThZ+Am2nOJr5toaczIJPbiw5AQo3yhvZ0=; b=tz+ZOUOL/WRnsRN25b4Fka9ske7ykNP7rGW0HZ/pvFGHnlW+Q6Jkru1DfW4PCxHRsq FP7GvPG32YeQRAyUIEMOFGkEZIwhJMW4B5f/oDPBxEocapnG0IwZO1EE5lPRCTrYGL3o xtYUPCcWcfaz/CLKbTksvS6XWWEPAojf/bpG9xQBk9tSU7a5HB91TYWp6UIzwYDDOKJE UsN6eEaLbRkEhTXQinYxMph4SAb6VHrVczmuj1WSFQPTPC108k9VbcDm3d8QULwFA9tW 4blOSnyJRezIF4JN+KwzbR13XmgxEJMLZ3VnxbfOxMutNxtAf4WZwlYAT6+uPOt8WGne RJXg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tsIy3s1g; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::229 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com. [2607:f8b0:4864:20::229]) by gmr-mx.google.com with ESMTPS id h26si39872oos.1.2021.06.21.18.52.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jun 2021 18:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::229 as permitted sender) client-ip=2607:f8b0:4864:20::229; Received: by mail-oi1-x229.google.com with SMTP id w1so8857994oie.13 for ; Mon, 21 Jun 2021 18:52:36 -0700 (PDT) X-Received: by 2002:aca:b1d4:: with SMTP id a203mr1072532oif.160.1624326755925; Mon, 21 Jun 2021 18:52:35 -0700 (PDT) Received: from MacBook-Pro-2.localdomain (71-33-153-196.hlrn.qwest.net. [71.33.153.196]) by smtp.gmail.com with ESMTPSA id o5sm2212651oti.53.2021.06.21.18.52.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jun 2021 18:52:35 -0700 (PDT) From: James Hilliard To: swupdate@googlegroups.com Cc: James Hilliard Subject: [swupdate] [PATCH v2 1/1] diskpart: improve partition diff logging Date: Mon, 21 Jun 2021 19:52:31 -0600 Message-Id: <20210622015231.21708-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Original-Sender: james.hilliard1@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tsIy3s1g; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::229 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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: , Signed-off-by: James Hilliard --- Changes v1 -> v2: - rebase on master to handle hybrid partitions --- handlers/diskpart_handler.c | 56 ++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c index acd21d4..22f005e 100644 --- a/handlers/diskpart_handler.c +++ b/handlers/diskpart_handler.c @@ -400,10 +400,42 @@ static int diskpart_append_hybrid_pmbr(struct fdisk_label *lb, struct fdisk_tabl return ret; } +static void diskpart_partition_info(struct fdisk_context *cxt, const char *name, struct fdisk_partition *pa) +{ + struct fdisk_label *lb; + int *ids = NULL; + size_t nids = 0; + size_t i; + lb = fdisk_get_label(cxt, NULL); + fdisk_label_get_fields_ids_all(lb, cxt, &ids, &nids); + if (ids && lb) { + TRACE("%s:", name); + for (i = 0; i < nids; i++) { + const struct fdisk_field *field = + fdisk_label_get_field(lb, ids[i]); + char *data = NULL; + if (!field) + continue; + if (fdisk_partition_to_string(pa, cxt, ids[i], &data)) + continue; + TRACE("\t%s: %s", fdisk_field_get_name(field), data); + free(data); + } + } else { + if (!ids) + ERROR("Failed to load field ids"); + if (!lb) + ERROR("Failed to load label"); + } + if (ids) + free(ids); +} + /* * Return true if partition differs */ -static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk_partition *secondpa) +static bool diskpart_partition_cmp(struct fdisk_context *cxt, struct fdisk_partition *firstpa, + struct fdisk_partition *secondpa) { struct fdisk_parttype *type; const char *lbtype; @@ -432,11 +464,9 @@ static bool diskpart_partition_cmp(struct fdisk_partition *firstpa, struct fdisk 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))) { - 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), - fdisk_partition_get_name(secondpa) ? fdisk_partition_get_name(secondpa) : "", - (long long unsigned)fdisk_partition_get_size(secondpa)); + TRACE("Partition differ:"); + diskpart_partition_info(cxt, "Original", firstpa); + diskpart_partition_info(cxt, "New", secondpa); return true; } return false; @@ -566,7 +596,7 @@ static int diskpart_fill_table(struct fdisk_context *cxt, struct diskpart_table /* * Return 1 if table differs, 0 if table is the same, negative on error */ -static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb) +static int diskpart_table_cmp(struct fdisk_context *cxt, struct fdisk_table *tb, struct fdisk_table *oldtb) { size_t numnewparts = fdisk_table_get_nents(tb); size_t numpartondisk = fdisk_table_get_nents(oldtb); @@ -590,7 +620,7 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb) fdisk_table_next_partition (oldtb, olditr, &pa)) { TRACE("Partition not found, something went wrong %lu !", i); ret = -EFAULT; - } else if (diskpart_partition_cmp(pa, newpa)) { + } else if (diskpart_partition_cmp(cxt, pa, newpa)) { ret = 1; } @@ -604,8 +634,8 @@ static int diskpart_table_cmp(struct fdisk_table *tb, struct fdisk_table *oldtb) return ret; } -static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_table *oldtb, - struct create_table *createtable) +static int diskpart_compare_tables(struct fdisk_context *cxt, struct diskpart_table *tb, + struct diskpart_table *oldtb, struct create_table *createtable) { int ret = 0; @@ -614,7 +644,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta * to check if they differ. */ if (!createtable->parent) { - ret = diskpart_table_cmp(tb->parent, oldtb->parent); + ret = diskpart_table_cmp(PARENT(cxt), tb->parent, oldtb->parent); if (ret < 0) return ret; else if (ret) @@ -622,7 +652,7 @@ static int diskpart_compare_tables(struct diskpart_table *tb, struct diskpart_ta } if (tb->child && !createtable->child) { - ret = diskpart_table_cmp(tb->child, oldtb->child); + ret = diskpart_table_cmp(cxt, tb->child, oldtb->child); if (ret < 0) return ret; else if (ret) @@ -844,7 +874,7 @@ static int diskpart(struct img_type *img, if (ret) goto handler_exit; - ret = diskpart_compare_tables(tb, oldtb, createtable); + ret = diskpart_compare_tables(cxt, tb, oldtb, createtable); if (ret) goto handler_exit;