Skip to content

Instantly share code, notes, and snippets.

@tkhai
Created February 27, 2020 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkhai/1c157243150357af3b57e7d87e79df6f to your computer and use it in GitHub Desktop.
Save tkhai/1c157243150357af3b57e7d87e79df6f to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <fcntl.h>
#include <stdint.h>
#define RWH_WRITE_LIFE_EXTREME 5
#define F_SET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 14)
#define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12)
#define F_LINUX_SPECIFIC_BASE 1024
main()
{
int fd1 = open("test1.tmp", O_RDWR|O_TRUNC|O_CREAT);
int fd2 = open("test2.tmp", O_RDWR|O_TRUNC|O_CREAT);
uint64_t h = RWH_WRITE_LIFE_EXTREME;
char buf[1024*1024];
if (fd1 < 0 || fd2 < 0) {
perror("open");
exit(1);
}
if (fcntl(fd1, F_SET_RW_HINT, &h)) {
perror("fcntl1");
exit(1);
}
if (fcntl(fd2, F_SET_RW_HINT, &h)) {
perror("fcntl2");
exit(1);
}
write(fd1, buf, 4096);
write(fd2, buf, sizeof(buf)-4096);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment