Bug 291377 - gpart: "gpart list --libxo=json" duplicates attribute keys
Summary: gpart: "gpart list --libxo=json" duplicates attribute keys
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Alan Somers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-12-03 21:54 UTC by Alan Somers
Modified: 2026-01-20 22:33 UTC (History)
0 users

See Also:
asomers: mfc-stable15+
asomers: mfc-stable14+
asomers: mfc-stable13-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2025-12-03 21:54:14 UTC
JSON forbids duplicating a field name, at least if you care about the value of the first instance of the field.  But currently, "gpart list --libxo=json" will print multiple "attrib" fields if a provider has multiple attributes set.  For example:

somers@fbsd-head ~> sudo gpart set -i 1 -a bootonce vtbd0
bootonce set on vtbd0p1
somers@fbsd-head ~> gpart show vtbd0
=>       40  155189168  vtbd0  GPT  (74G)
         40          8         - free -  (4.0K)
         48       1024      1  freebsd-boot  [bootonce,bootme]  (512K)
       1072  146800640      2  freebsd-ufs  (70G)
  146801712    8387488      3  freebsd-swap  (4.0G)
  155189200          8         - free -  (4.0K)
somers@fbsd-head ~> > gpart list --libxo=json,pretty
...
        {
          "name": "vtbd0p1",
          "mediasize": 524288,
          "sectorsize": 512,
          "stripesize": 8192,
          "stripeoffset": 0,
          "mode": "r0w0e0",
          "efimedia": "HD(1,GPT,b8949974-4a7e-11e9-ba65-e03f4944d7b6,0x30,0x400)
",
          "rawuuid": "b8949974-4a7e-11e9-ba65-e03f4944d7b6",
          "rawtype": "83bd6b9d-7f41-11dc-be0b-001560b84f0f",
          "attrib": "bootonce",
          "attrib": "bootme",
          "label": "",
          "length": "524288",
          "offset": "24576",
          "type": "freebsd-boot",
          "index": "1",
          "end": "1071",
          "start": "48"
        },
...

Notice the two "attrib" fields.  They should be changed to a single field.
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-12-10 18:12:18 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a0347b0f3a6088872c29eddb85154478d543dffb

commit a0347b0f3a6088872c29eddb85154478d543dffb
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2025-12-05 16:16:53 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2025-12-10 18:08:30 +0000

    gpart: "gpart --libxo:JP list" duplicates attribute keys

    Add leaf-list modifier to attrib as it's possible to have multiple
    attributes on a gpart provider.

    I purposely made it so that the normal output still says "attrib:" just
    so we don't break any scripts people may be using to parse the output,
    but the libxo output now says "attribute" just like `gpart show` will do
    once https://reviews.freebsd.org/D53950 is merged.

    PR:             291377
    MFC after:      1 week
    Reviewed by:    asomers
    Sponsored by:   ConnectWise
    Differential Revision: https://reviews.freebsd.org/D54080

 sbin/geom/core/geom.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2026-01-20 17:14:35 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b44f04225bc3f2ca33cff90273b8cdfea67774e

commit 3b44f04225bc3f2ca33cff90273b8cdfea67774e
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2025-12-05 16:16:53 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2026-01-20 17:12:53 +0000

    gpart: "gpart --libxo:JP list" duplicates attribute keys

    Add leaf-list modifier to attrib as it's possible to have multiple
    attributes on a gpart provider.

    I purposely made it so that the normal output still says "attrib:" just
    so we don't break any scripts people may be using to parse the output,
    but the libxo output now says "attribute" just like `gpart show` will do
    once https://reviews.freebsd.org/D53950 is merged.

    PR:             291377
    Reviewed by:    asomers
    Sponsored by:   ConnectWise
    Differential Revision: https://reviews.freebsd.org/D54080

    (cherry picked from commit a0347b0f3a6088872c29eddb85154478d543dffb)

 sbin/geom/core/geom.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-01-20 22:32:18 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=46a760e578f553d54c2e2ef6b295d3e9c71bd558

commit 46a760e578f553d54c2e2ef6b295d3e9c71bd558
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2025-12-05 16:16:53 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2026-01-20 22:31:29 +0000

    gpart: "gpart --libxo:JP list" duplicates attribute keys

    Add leaf-list modifier to attrib as it's possible to have multiple
    attributes on a gpart provider.

    I purposely made it so that the normal output still says "attrib:" just
    so we don't break any scripts people may be using to parse the output,
    but the libxo output now says "attribute" just like `gpart show` will do
    once https://reviews.freebsd.org/D53950 is merged.

    PR:             291377
    Reviewed by:    asomers
    Sponsored by:   ConnectWise
    Differential Revision: https://reviews.freebsd.org/D54080

    (cherry picked from commit a0347b0f3a6088872c29eddb85154478d543dffb)

 sbin/geom/core/geom.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)