summaryrefslogtreecommitdiff
path: root/util
AgeCommit message (Collapse)Author
21 hoursutil/nvmutil: more sensible errno initLeah Rowe
just use errno itself as input to err if unset, it's set to ECANCELED anyway i really should rewrite the error handling to not use errno at some point. it's a bit unreliable, on some unix systems. Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: proper errno status on prw()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
22 hoursutil/nvmutil: reset errno if EINTR on lseekLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
23 hoursutil/nvmutil: stricter errno on prw()Leah Rowe
we want the first error to be the one shown, when returning negative Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix printf c89/c90 specifiersLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: reset part_validLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: restore errno if lseek resets itLeah Rowe
if it resets it on success, that is! theoretically possible. we must preserve errno. normally i'm a bit more casual about it, but this function is replicating libc, so i must be strict Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix another printf specifierLeah Rowe
ditto to last commit Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: fix bad print specifier (c90)Leah Rowe
size_t may be unsigned long long, but lu is for unsigned long. the integer is small enough that we don't need to worry, so let's just cast it accordingly (inside err) Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: only inc num_invalid on bad checksumLeah Rowe
this fixes a regression that i introduced Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: restore errno on failed offset restoreLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: don't leave part_valid untouchedLeah Rowe
always set it. the current logic only sets it if valid, but invalid doesn't, relying on global initialisation. this check sets it explicitly. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: remove unused st variableLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: check whether a file is a fileLeah Rowe
and not, say, a socket or a directory, or a character device, or something else. Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil: preserve errno during i/oLeah Rowe
do not clobber errno yeah we're basically being libc now Signed-off-by: Leah Rowe <leah@libreboot.org>
24 hoursutil/nvmutil prw: always restore original offsetLeah Rowe
it currently only does so on success, but errors will leave the file descriptor corrupted. reset it accordingly. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: err if file offset failsLeah Rowe
currently it returns success, if restoring a previous offset failed. this leaves descriptor corrupted when the caller thinks otherwise return -1 instead, so that the caller can treat it as an error, relying on whatever lseek had set for errno Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: fix buffer overread in prw()Leah Rowe
edge case scenario, unlikely to actually trigger. now impossible to trigger. Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: fix rc overflow bug in rw_file_exactLeah Rowe
check that it's below len, not above it. that way, it will now exit if it goes above (which it shouldn't, but it theoretically could if the code was changed and there was a regression or subtle edge case) Signed-off-by: Leah Rowe <leah@libreboot.org>
25 hoursutil/nvmutil: use C90 instead of C99Leah Rowe
with the other changes made recently, super old compilers now work. yes, i needed to change some specifiers in printf. typedefs provided for uint, and a define included X OPEN SOURCE 500. and asserts for integers. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: define O_BINARY flagLeah Rowe
use it Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: fix indent on ifdefsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: define SIZE_MAX if not definedLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: remove arc4random for portabilityLeah Rowe
just use /dev/urandom and fall back to /dev/random this is what i was doing for years. this combined with other changes, and the new prw() function for i/o, means portability should be pretty high now. i will actually start testing nvmutil on old bsd systems from the 90s later. Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: portable pread/pwriteLeah Rowe
not thread-safe lucky we're single-threaded! Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hourswipLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
26 hoursutil/nvmutil: more reliable stdint.h checkLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: reset errno before run_cmdLeah Rowe
in case any stale errors are present. at this point, we know that the code is likely safe and that nothing happened, because we quite obsessively call err() before that point. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: explicitly check cmd nullptrLeah Rowe
null isn't guaranteed to be zero Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: safer SSIZE_MAX defineLeah Rowe
the current one assumes two's compliment and no padding bits. i assert two's compliment earlier in code, but it doesn't guarantee: sizeof(ssize_t) == sizeof(size_t) it's theoretically possible that size_t=64 and ssize_t=32, and then the macro would break. this new version uses SIZE_MAX instead, without subtraction, but halves it using a bit shift. this may still break, but it should work nicely. Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: fix a bad cast (or lack thereof)Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: err if unsupported rw_type on i/oLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: rename badly named off_t assertLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: assert two's compliment integersLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: add assert for intLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/nvmutil: add assert for off_tLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursRevert "util/nvmutil: don't use zx printf specifier"Leah Rowe
This reverts commit ba3cf14faa0c1e55e82d92795a07ec82eb121fcf.
29 hoursutil/nvmutil: explain errval handling in err()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: make rc size_t (not ssize_t)Leah Rowe
i overlooked this when writing. it's comparing to a length which is size_t, so let's avoid an unnecessary cast. Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: don't use zx printf specifierLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: add portable asserts for integersLeah Rowe
we need this to be the case for our code, that char and uint8_t are 8 bits, and that uint16_t and uint32_t are 16- and 32-bit. these asserts protect us in case it's not (it will cause a compile time error). Signed-off-by: Leah Rowe <leah@libreboot.org>
29 hoursutil/nvmutil: abort if I/O len exceeds SSIZE_MAXLeah Rowe
in rw_file_exact otherwise, if length exceeds SSIZE_MAX, we could hit an overflow the buffers and lengths we deal with are relatively small anyway, so this fix is preventative Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: annotate the prototypesLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/nvmutil: unified gbe file part I/OLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/nvmutil: remove stale defineLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/nvmutil: unified I/O: stdout, urandom and gbeLeah Rowe
everything is a file Signed-off-by: Leah Rowe <leah@libreboot.org>
32 hoursutil/nvmutil: unified urandom/gbe file readingLeah Rowe
like before, but with the newly correct logic Signed-off-by: Leah Rowe <leah@libreboot.org>
32 hoursutil/nvmutil: safer read_gbe_file_exactLeah Rowe
it now retries infinitely on EINTR, except when the return of pread is precisely zero, at which point it errs. this is better than having an arbitrary maximum like before, and increases robustness on unreliable file systems, e.g. NFS shares. Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: report checksum in cmd_dumpLeah Rowe
as it should be! Signed-off-by: Leah Rowe <leah@libreboot.org>
33 hoursutil/nvmutil: reduce checksum report verbosityLeah Rowe
only print a message what arg_part is set. this means that a checksum error message won't be printed on cat commands. Signed-off-by: Leah Rowe <leah@libreboot.org>