Skip to content

btrfs tools: share the helpers the twelve tools were repeating - #142

Draft
Yury-MonZon wants to merge 3 commits into
devfrom
btrfs-tools-shared-helpers
Draft

btrfs tools: share the helpers the twelve tools were repeating#142
Yury-MonZon wants to merge 3 commits into
devfrom
btrfs-tools-shared-helpers

Conversation

@Yury-MonZon

@Yury-MonZon Yury-MonZon commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Three small DRY passes over the twelve btrfs tools, no behaviour change intended.

  • current_subvol() / current_fsuuid() replace bare findmnt -nro FSROOT / and findmnt -nro UUID /
    calls. findmnt stays the first source, since it needs no privileges and is authoritative on a booted
    system, but it cannot answer inside a chroot and reports the path recorded at mount time, so the
    helpers fall back to asking btrfs. flipper-bls.sh keeps its own copy on purpose, because
    kernel-install hooks source it without this lib.
  • stamp() replaces the four copies of date +%Y-%m-%d_%H-%M-%S that name snapshots, aside copies and
    ro sends. list-profiles classifies KIND=old by matching that exact shape, so the format needs one
    definition rather than four. path_of_uuid() takes over send-snapshot's private uuid-to-path scan.
  • HELP_YES / HELP_DEVICE hold the two option lines that ten tools repeated verbatim, so the wording
    cannot drift. migrate-profile spells its own out, since its -y also decides what happens to
    conflicts.
    as one branch on hardware across five builds; splitting preserved the final tree byte for byte.

Split out of the closed #141. Only the combined final state was run on hardware; each
commit parses and defines the helpers it uses, and the stack tip is byte-identical to what
was tested.

current_subvol()/current_fsuuid() replace the bare `findmnt -nro FSROOT /` and
`findmnt -nro UUID /` calls in create-profile, create-snapshot and migrate-profile.
findmnt reads /proc/self/mountinfo, needs no privileges and is authoritative on a
booted system, so it stays the first source; it cannot answer inside a chroot and
reports the path recorded at mount time, so the helpers fall back to `btrfs
subvolume show /` and `btrfs filesystem show /`, which resolve live.
flipper-bls.sh keeps its own copy deliberately, since kernel-install hooks source
it without flipper-btrfs.sh; the comment now says so.
stamp() replaces the four copies of `date +%Y-%m-%d_%H-%M-%S` that name snapshots,
aside copies and ro sends: list-profiles keys KIND=old off that exact shape, so the
format needs one definition. path_of_uuid() takes over send-snapshot's private
parent_path_of body, putting the uuid -> path scan of `btrfs subvolume list` in the
lib next to build_uuid_map.
Ten tools repeated the -d,--device line and three the -y,--yes line verbatim in
their usage() text (btrfs-maintenance with a column of drift). HELP_YES/HELP_DEVICE
hold them in flipper-btrfs.sh and the heredocs interpolate them, so the wording
cannot diverge. migrate-profile spells its own out: its -y also decides what
happens to conflicts, and its help column is wider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant