Skip to content

Instantly share code, notes, and snippets.

@tomato42
Created March 9, 2015 22:01
Show Gist options
  • Save tomato42/74dca1f30c50d27a5da5 to your computer and use it in GitHub Desktop.
Save tomato42/74dca1f30c50d27a5da5 to your computer and use it in GitHub Desktop.
Utility to fill up XFS file system without writing data to disk
/*
* xfs-bloat.c
*
* Create a file that allocates a large amount of space on an XFS file system.
*
* Compilation:
* gcc -Wall xfs-bloat.c -o xfs-bloat
*/
#include <xfs/xfs.h>
#include <xfs/xfs_fs.h>
#include <stdio.h>
#define TEBIBYTE 1024*1024*1024*1024LL
int main(int argc, char **argv)
{
int fd;
int ret;
if (argc != 2) {
printf("Usage: xfs-bloat <filename>\n");
printf("\n");
printf("Preallocate a 1TiB file without actually writing data to "
"disk\n");
return 1;
}
fd = open(argv[1], O_CREAT|O_RDWR|O_EXCL, S_IRUSR|S_IWUSR);
if (fd == -1) {
printf("Creating file failed\n");
return 1;
}
ret = platform_test_xfs_fd(fd);
if (ret != 1) {
printf("Opened file does not reside on XFS: %i\n", ret);
return 1;
}
ret = platform_test_xfs_path(argv[1]);
if (ret != 1) {
printf("File does not reside on XFS: %i\n", ret);
return 1;
}
xfs_flock64_t flag = {0};
flag.l_whence = SEEK_SET;
flag.l_start = 0;
flag.l_len = TEBIBYTE;
ret = xfsctl(argv[1], fd, XFS_IOC_RESVSP64, &flag);
if (ret != 0) {
printf("Call to xfsctl failed: %i\n", ret);
return 1;
}
if (close(fd) == -1) {
printf("Closing the file failed\n");
return 1;
}
printf("%s file created\n", argv[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment