Created
December 12, 2022 16:09
-
-
Save GavinRay97/5da61ca8bfce9aad5e3c1db1f0c57775 to your computer and use it in GitHub Desktop.
Linux 6.1 new Direct IO (DIO) "statx" file information example
This file contains hidden or 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> // open, O_CREAT, O_RDWR, AT_FDCWD, AT_STATX_SYNC_AS_STAT | |
#include <stdio.h> // printf | |
#include <sys/stat.h> // statx, STATX_ALL | |
#include <unistd.h> // pwrite | |
#define TMPFILE "test.txt" | |
int | |
main() | |
{ | |
// Create a temporary file called "test.txt" | |
int fd; | |
if (-1 == (fd = open(TMPFILE, O_CREAT | O_RDWR, 0666))) | |
{ | |
perror("open"); | |
return 1; | |
} | |
// Write 10 bytes to the file | |
if (10 != pwrite(fd, "0123456789", 10, 0)) | |
{ | |
perror("pwrite"); | |
return 1; | |
} | |
// Get the file descriptor | |
struct statx statxbuf; | |
if (0 != statx(AT_FDCWD, TMPFILE, AT_STATX_SYNC_AS_STAT, STATX_ALL, &statxbuf)) | |
{ | |
perror("statx"); | |
return 1; | |
} | |
printf("File size: %llu \n", statxbuf.stx_size); | |
printf("Direct IO: mem-alignment=%u, offset-alignment=%u \n", | |
statxbuf.stx_dio_mem_align, | |
statxbuf.stx_dio_offset_align); | |
return 0; | |
} |
This file contains hidden or 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
[user@MSI dio-test]$ clang main.cpp -o main | |
[user@MSI dio-test]$ ./main | |
File size: 10 | |
Direct IO: mem-alignment=XXX, offset-alignment=XXX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kernel commit: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=825cf206ed510c4a1758bef8957e2b039253e2e3