Skip to content

Instantly share code, notes, and snippets.

@heatd
Created October 3, 2022 13:57
Show Gist options
  • Save heatd/e15173363613076074634df493bd0f9c to your computer and use it in GitHub Desktop.
Save heatd/e15173363613076074634df493bd0f9c to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
int main()
{
int fd = open("test", O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
return 1;
ftruncate(fd, 0x100000);
int c = 10;
write(fd, &c, sizeof(c));
pwrite(fd, &c, sizeof(c), 0x100000);
fsync(fd);
struct stat buf;
fstat(fd, &buf);
printf("Blocks: %lu\n", buf.st_blocks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment