Skip to content

Commit

Permalink
fixup! [LibOS] Make handling of corruption more consistent (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: g2flyer <[email protected]>
  • Loading branch information
g2flyer committed Aug 26, 2024
1 parent f15133b commit 62543cd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions libos/test/fs/pf_tamper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "common.h"

static void read_complete_file(const char* path) {
int fd = open(path, O_RDONLY);
if (fd < 0) {
printf("ERROR: Failed to open input file %s: %s\n", path, strerror(errno));
return;
}

char buf[1024];
while (true) {
ssize_t ret = read(fd, buf, sizeof(buf));
if (ret < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
printf("ERROR: Failed to read file %s: %s\n", path, strerror(errno));
return;
}
if (ret == 0)
break;
}

if (close(fd) != 0)
printf("ERROR: Failed to close file %s: %s\n", path, strerror(errno));
}


int main(int argc, char* argv[]) {
if (argc < 2)
fatal_error("Usage: %s <file_path>\n", argv[0]);

setup();
read_complete_file(argv[1]);
return 0;
}

0 comments on commit 62543cd

Please sign in to comment.