static void mfd_assert_shrink(int fd) { int r, fd2; r = ftruncate(fd, MFD_DEF_SIZE / 2); if (r < 0) { printf("ftruncate(SHRINK) failed: %m\n"); abort(); } mfd_assert_size(fd, MFD_DEF_SIZE / 2); fd2 = mfd_assert_open(fd, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); close(fd2); mfd_assert_size(fd, 0); }
static void mfd_assert_grow_write(int fd) { static char buf[MFD_DEF_SIZE * 8]; ssize_t l; l = pwrite(fd, buf, sizeof(buf), 0); if (l != sizeof(buf)) { printf("pwrite() failed: %m\n"); abort(); } mfd_assert_size(fd, MFD_DEF_SIZE * 8); }
static void mfd_assert_grow(int fd) { int r; r = ftruncate(fd, MFD_DEF_SIZE * 2); if (r < 0) { printf("ftruncate(GROW) failed: %m\n"); abort(); } mfd_assert_size(fd, MFD_DEF_SIZE * 2); r = fallocate(fd, 0, 0, MFD_DEF_SIZE * 4); if (r < 0) { printf("fallocate(ALLOC) failed: %m\n"); abort(); } mfd_assert_size(fd, MFD_DEF_SIZE * 4); }
static void mfd_assert_grow_write(int fd) { static char *buf; ssize_t l; /* hugetlbfs does not support write */ if (hugetlbfs_test) return; buf = malloc(mfd_def_size * 8); if (!buf) { printf("malloc(%zu) failed: %m\n", mfd_def_size * 8); abort(); } l = pwrite(fd, buf, mfd_def_size * 8, 0); if (l != (mfd_def_size * 8)) { printf("pwrite() failed: %m\n"); abort(); } mfd_assert_size(fd, mfd_def_size * 8); }