This patch series adds support for storing the GRUB environment block in
a reserved area of the Btrfs header. On copy on write filesystems such
as Btrfs, the normal file based envblk cannot be updated safely at
runtime because block addresses are not stable. The reserved area
provides a fixed location that GRUB can write directly, allowing
commands such as grub-reboot and savedefault to work on Btrfs volumes.
The series proceeds in small chunks to keep each change buildable and
easier to review. The first patches add new data structures and helpers
for creating, opening, and writing an environment block in the reserved
area. Later patches update set_variables, unset_variables, and
list_variables so they can use the external block when it is present. An
entry is added to the Btrfs header to reserve space at 256 KiB for the
environment block. Finally, grub.cfg is modified so that load_env and
save_env use the external block automatically when env_block is defined.
The first two patches are new in this series as feedback from the review
to use a portable string specifier for size_t. Unfortunately the z
length modifier is missing in GRUB printf routine's format specifier.
The new patches add support and test case for that. In theory they can
be reviewed separately.
And also yet another new patch "btrfs: update doc link for bootloader
support" added at the end to address v3 review feedback.
v2:
- Define ENV_BTRFS_OFFSET as 256*1024
- Do not conflate type and variable definitions
- Align typedef with struct declaration to follow coding style
- Use bool as the return type of is_abstraction()
- Add "if (dev->disk != NULL)" check in is_abstraction()
- Refine the loop logic in is_abstraction() tests
- Remove extra indentation and redundant lines in read_envblk_fs
- Use off_t and size_t for offset and size variables, fix similar cases
throughout
- Use explicit check "(fp == NULL)" instead of "(! fp)", fix similar
cases throughout
- Use bool for the "found" field in var_lookup_ctx
- Add documentation describing the Btrfs environment block and special
environment block variables
v3:
- Replace !fp with explicit (fp == NULL) for clarity
- Fix missing blank line before return statement
- Fix missing space after cast operator
v4:
- Rename ENV_BTRFS_OFFSET to GRUB_ENV_BTRFS_OFFSET
- Move GRUB_ENV_BTRFS_OFFSET into "btrfs: add environment block to
reserved header area"
- Adjust patch order to resolve relocated GRUB_ENV_BTRFS_OFFSET
- Add patch "btrfs: update doc link for bootloader support"
- Do better typedef
- Add heads-up comments to both fs_envblk_spec and btrfs_head that they
have to stay in sync
- Fix a few places to use explicit checks for NULL, true/false etc
- Use goto labels to cleanup consistently
- Mark function names with trailing "()" in commits and comments
- Rename envblk_fs to envblk_on_block for better clarity
- Avoid redundant curly braces in if .. else if clause
- Highlight overflow guard around envioronment block in embed_region
- Rename a few functions for clarity
- Use portable printf formats for off_t and size_t
- Support z length modifier in GRUB printf format string
- Add z modifier to printf unit test
Michael Chang (12):
misc: add z length modifier support
tests: add z modifier printf tests
btrfs: add environment block to reserved header area
util/grub-editenv: add basic structures and probe call for external
envblk
util/grub-editenv: add fs_envblk open helper
util/grub-editenv: add fs_envblk write helper
util/grub-editenv: wire set_variables to optional fs_envblk
util/grub-editenv: wire unset_variables to optional fs_envblk
util/grub-editenv: wire list_variables to optional fs_envblk
00_header.in: wire grub.cfg to use env_block when present
docs: add Btrfs env block and special env vars
btrfs: update doc link for bootloader support
docs/grub.texi | 60 ++++++
grub-core/fs/btrfs.c | 12 +-
grub-core/kern/misc.c | 20 ++
include/grub/fs.h | 2 +
tests/printf_unit_test.c | 10 +
util/grub-editenv.c | 407 ++++++++++++++++++++++++++++++++++++++-
util/grub.d/00_header.in | 26 ++-
7 files changed, 528 insertions(+), 9 deletions(-)
--
2.51.0
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel