Skip to content

Instantly share code, notes, and snippets.

@hemantkchitale
Created April 17, 2019 03:53
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 hemantkchitale/b16ff4691e4f82e6dc8d419878827ac2 to your computer and use it in GitHub Desktop.
Save hemantkchitale/b16ff4691e4f82e6dc8d419878827ac2 to your computer and use it in GitHub Desktop.
Create MultiGB File
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
long int sz;
char *fname;
int ret,fd;
if (argc != 3)
{
fprintf(stderr, "usage: %s FILENAME new-size-in-gigabytes -- fractions not allowed\n", argv[0]);
fprintf(stdout, "(c) Hemant K Chitale\n");
return(-1);
}
fname = argv[1];
sz = atol(argv[2]);
if ((ret = (fd = open(fname, O_RDWR | O_CREAT | O_EXCL, 0666))) == -1 ) {
perror("open");
return(ret);
}
if ( (ret = fallocate( fd, 0, (loff_t)0, (loff_t)sz * 1024 * 1024 * 1024 )) != 0 ){
perror ("fallocate");
unlink( fname );
return(ret);
}
close(fd);
fprintf(stdout, "File Created. This utility (c) Hemant K Chitale\n");
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment