Skip to content

Instantly share code, notes, and snippets.

@nmmmnu
Created May 9, 2020 13:40
Show Gist options
  • Save nmmmnu/0225562bd1bead91dfc5f74845e4bf64 to your computer and use it in GitHub Desktop.
Save nmmmnu/0225562bd1bead91dfc5f74845e4bf64 to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <fcntl.h> // open
#include <stdlib.h> // fallocate
#include <stdio.h>
inline void err(const char *msg){
perror(msg);
exit(1);
}
off_t const size = 1024 * 1024 * 1024;
int main(void){
int fd = open("testfile", O_RDWR | O_TRUNC | O_CREAT, 0644);
if (fd < 0)
err("open");
if (fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, 8 * size) < 0)
err("fallocate");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment