Created
October 3, 2022 13:57
-
-
Save heatd/e15173363613076074634df493bd0f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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