Skip to content

Instantly share code, notes, and snippets.

@ajkr
Created September 18, 2020 01:00
Show Gist options
  • Save ajkr/2eac6fe4d918d0c8819e9656ec4eab41 to your computer and use it in GitHub Desktop.
Save ajkr/2eac6fe4d918d0c8819e9656ec4eab41 to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <linux/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char** argv) {
if (argc != 3) {
fprintf(stderr, "%s <path> <num iters>\n", argv[0]);
exit(1);
}
const char* path = argv[1];
int num_iters = atoi(argv[2]);
for (int i = 0; i < num_iters; ++i) {
if (unlink(path) == -1 && i != 0) {
perror("unlink");
exit(1);
}
int fd;
if ((fd = open(path, O_CREAT)) == -1) {
perror("open");
exit(1);
}
struct stat st;
if (fstat(fd, &st) == -1) {
perror("fstat");
exit(1);
}
int gen = 0;
if (ioctl(fd, FS_IOC_GETVERSION, &gen) == -1) {
gen = -1;
}
if (close(fd) == -1) {
perror("close");
exit(1);
}
fprintf(stdout, "%d,%d\n", st.st_ino, gen);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment