Files
vasilito b9874d0941 feat: USB storage read/write proof + full Red Bear OS tree sync
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.
2026-05-03 23:03:24 +01:00

59 lines
1.6 KiB
C

#include <stdio.h>
#include <assert.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include "test_helpers.h"
int main(void) {
// Spawn three childrens, one with same pgid and two with pgid set to its own
// pid, so the exit order is two different pgid, then followed with same pgid
pid_t pid_samepgid = fork();
ERROR_IF(fork, pid_samepgid, == -1);
if (pid_samepgid == 0) {
// child
usleep(300000);
_Exit(2);
}
pid_t pid_diffpgids[2];
for (int i = 0; i < 2; i++) {
pid_diffpgids[i] = fork();
ERROR_IF(fork, pid_diffpgids[i], == -1);
if (pid_diffpgids[i] == 0) {
int ret = setpgid(0, 0);
ERROR_IF(setpgid, ret, == -1);
// child
usleep((i + 1) * 100000);
_Exit(i);
}
}
int status;
pid_t wid;
// First, check that the first different-pgid proc is recognized.
wid = waitpid(-1, &status, 0);
ERROR_IF(waitpid, wid, == -1);
assert(wid == pid_diffpgids[0]);
assert(WIFEXITED(status));
assert(WEXITSTATUS(status) == 0);
// Then, check that the longest-waiting proc with the same pgid is properly matched.
wid = waitpid(0, &status, 0);
ERROR_IF(waitpid, wid, == -1);
assert(wid == pid_samepgid);
assert(WIFEXITED(status));
assert(WEXITSTATUS(status) == 2);
// Finally, the last different-pgid must have completed.
wid = waitpid(-1, &status, WNOHANG);
ERROR_IF(waitpid, wid, == -1);
assert(wid == pid_diffpgids[1]);
assert(WIFEXITED(status));
assert(WEXITSTATUS(status) == 1);
}