Skip to content

Commit

Permalink
Raise an error if vmm_disk_space overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
reynir committed Sep 18, 2024
1 parent 9cb73b1 commit 83fd12f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vmm_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <caml/unixsupport.h>

#include <unistd.h>
#include <errno.h>

CAMLprim value vmm_cpu_count (value unit) {
CAMLparam1(unit);
Expand Down Expand Up @@ -59,6 +60,11 @@ CAMLprim value vmm_disk_space (value path) {
const char *p = String_val(path);
if (statfs(p, &s) < 0)
uerror("statfs", Nothing);
int r = to_mb(s.f_blocks, s.f_bsize);
if (r < 0) {
errno = EOVERFLOW;
uerror("statfs", Nothing);
}
CAMLreturn(Val_int(to_mb(s.f_blocks, s.f_bsize)));
}

0 comments on commit 83fd12f

Please sign in to comment.