b9874d0941
Add redbear-usb-storage-check in-guest binary that validates USB mass storage read and write I/O: discovers /scheme/disk/ devices, writes a test pattern to sector 2048, reads it back, verifies match, restores original content. Updates test-usb-storage-qemu.sh with write-proof verification step. Includes all accumulated Red Bear OS work: kernel patches, relibc patches, driver infrastructure, DRM/GPU, KDE recipes, firmware, validation tooling, build system hardening, and documentation.
62 lines
1.3 KiB
C
62 lines
1.3 KiB
C
#include <err.h>
|
|
#include <errno.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
// does not compile with glibc
|
|
#ifndef __GLIBC__
|
|
|
|
__attribute__((nonnull(2)))
|
|
static void vwarn_test(int code, const char* fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
vwarnc(code, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
static void log_to_stdout(void) {
|
|
err_set_file(stdout);
|
|
warnc(ENOENT, "Dang it, Bobby.");
|
|
err_set_file(NULL);
|
|
}
|
|
|
|
void user_callback(int code) {
|
|
printf("Exiting due to error code: %d\n", code);
|
|
}
|
|
|
|
int main(void) {
|
|
err_set_exit(user_callback);
|
|
|
|
// Set errno to a known value for verifiable messages
|
|
// (Also, "Owner died" is just too funny not to use)
|
|
errno = EOWNERDEAD;
|
|
|
|
warn("Ran out of coffee");
|
|
warnx("%s pulled out your ethernet cable", "Cat");
|
|
warnc(EACCES, "Eat %d cookies", 42);
|
|
|
|
vwarn_test(EBADE, "Potato, %s", "krumpli");
|
|
|
|
// Set the sink to stdout then back to stderr
|
|
log_to_stdout();
|
|
warnc(EPERM,
|
|
"I'm sorry, Dave. I'm afraid I can't do that."
|
|
);
|
|
|
|
// As long as one err function works they should all work since
|
|
// two functions handle everything internally.
|
|
errc(EXIT_SUCCESS, EUSERS, "Bye. It's crowded.");
|
|
|
|
|
|
// Unreachable
|
|
puts("err did not exit");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
#else
|
|
int main(void) {
|
|
exit(0);
|
|
}
|
|
#endif
|