Leah Rowe
0867507fc8
util/nvmutil: don't check write checksums on partial
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
3fba84ad95
util/nvmutil: don't recurse err/close_files
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
897c7490b5
util/nvmutil: restore pad before reading to it
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
bae8999b80
util/nvmutil: don't show checksum on bad pwrite
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
6c29a07ca0
util/nvmutil: always restore saved errno
...
the last lseek there is only there to reset
state, so its errors are irrelevant.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
a12f502af8
util/nvmutil: post-write verification report
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
2f80ac76ae
util/nvmutil: optimise fsync / write check
...
write all at once, then sync all at once,
then verify all at once.
this increases the chancce that all data
gets written first, in the case of power
less, because fsync may take a while on
some systems.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
7c73218438
util/nvmutil: set EIO on bad memcmp
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
3f17cd3ebc
util/nvmutil: split up rw_gbe_file_part
...
the post-verification stage deserves a function
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
df18e65835
util/nvmutil: detect partial gbe rw
...
we already covered this in prw() which is
what ultimately gets called, but still.
it's logically correct not to check it here.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
fe16b79537
util/nvmutil: verify gbe contents after writing
...
read it back and check. sync to disk first.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
ce13599b99
util/nvmutil: consistent types
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
637d9a09c0
util/nvmutil: handle zero return in rw_file_exact
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
0cceb58867
util/nvmutil: rename lseek_eintr
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
8a7d73c223
util/nvmutil: fix lseek eintr err check
...
it should be is equal, not not equal
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
100cb2014e
util/nvmutil: rename err_eagain() to try_err()
...
makes more sense in code
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
b345caa25c
util/nvmutil: make EINTR configurable in prw()
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
4a5a3bae45
util/nvmutil: tidy up prw()
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
fe959f9fb8
util/nvmutil: extra overflow check in prw
...
compliant posix systems should never meet this
check, but i put it here.
spec != implementation
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
b60c42dcd0
util/nvmutil: extra overflow check in prw
...
do it at the very end
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
742b39be8c
util/nvmutil: handle EAGAIN in prw()
...
the cat function can be greatly simplified
handle it conditionally, because not all
functions should use it
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
7e8f375d9a
util/nvmutil: split up rw_file_exact
...
move the gbe-specific parts out of it
what remains is a relatively generic
function; a very conservative implementation,
wrapping around libc functions but with
a few additional safety checks.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
e71f977468
util/nvmutil: add negative off check to prw
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
fb57cedded
util/nvmutil: also do libc check on normal io
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
2a83a8ec43
util/nvmutil: properly reset lseek on error
...
don't return. set r instead. this will fall through
and return the same way, but with proper reset.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
935d082a51
util/nvmutil: move libc check to prw()
...
this still gets done from rw_once, but
it's generic enough that we want it in
our prw() wrapper function.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
07fa9bbc1f
util/nvmutil: remove io_args()
...
most of it can be done in rw_file_once
truly general checks have been moved to prw(),
so that the function is more general purpose.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
4bb64c8d37
util/nvmutil: move EINTR handle to prw()
...
this way, we now have a universal function
that is reusable elsewhere, with the same
redundancy. the rw_once and rw_exact functions
still get this redundancy, through prw
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
223932c5f8
util/nvmutil: simplify i/o
...
we can just fall through to nrw and decide
what function ta call there - either read/write
immediately and return, or fall back to the
portable positional implementation.
this also means we don't have to call io_args
in every function, since everything now runs
through prw()
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
8071d7eaa8
util/nvmutil: cast rnum pointer check
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
74077f9903
util/nvmutil: allow ushort to be 32-bit
...
no need to limit it here
rename ux to uint. no number specified.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
4c0ec27b4e
util/nvmutil: fix int assert
...
it can be higher than 32-bit, it's fine
the current check breaks some newer systems
accordingly, u32 becomes ux, x meaning x bits
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
dc6df36fe5
util/nvmutil: more asserts
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
23fee345fd
util/nvmutil: nicer typedefs
...
now that i'm not using stdint, i can use sane
typedef names
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
9cfae27bf4
util/nvmutil: remove stdint feature macro
...
and remove stdint
i don't need it. i typedef these ints myself
and i assert their size
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
888107764d
util/nvmutil: safer offset check (use subtraction)
...
don't allow overflows
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
abc484713a
util/nvmutil: check null pointer in io_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
e1cd978f01
util/nvmutil: check overflow in io_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
5f8593b581
util/nvmutil: fix offset validation
...
i didn't take into account partial writes, in io_args
this fixes it
unfortunately, this means i have to loosen the offset
check a bit, but it's fine
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
6ad09f55e0
util/nvmutil: restrict pointers in io_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
8e555f444c
util/nvmutil: check gbe file type before write
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
47936f52e9
util/nvmutil: check gbe file size before write
...
re-check. very unlikely since the program doesn't run
for very long, but we have to check if the file has
changed. this is a basic check of file size.
we could probably check the contents too, but that
would be overkill.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
551470cf6f
util/nvmutil: lock gbe file
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
afcdae1350
util/nvmutil: don't allow symlinks
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
98466398f9
nvmutil: fix bound check in last commit
...
i was fixing the size, but it should be calculated
properly.
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
e44b297db5
util/nvmutul: remove unused arg in io_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
83f67bf02a
util/nvmutil: block bad offset in io_args
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
14ab4c1b25
util/nvmutil: stricter i/o arg checks
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
386f715a29
util/nvmutil: stricter i/o length check
...
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00
Leah Rowe
d8be79432c
util/nvmutil: rename len to nrw in i/o
...
consistent with prw()
i prefer nrw (number of rw operations)
Signed-off-by: Leah Rowe <leah@libreboot.org >
2026-03-26 06:59:41 +00:00