Created
April 17, 2019 03:53
-
-
Save hemantkchitale/b16ff4691e4f82e6dc8d419878827ac2 to your computer and use it in GitHub Desktop.
Create MultiGB File
This file contains 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 <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