1 /* fallocate.c - Preallocate space to a file 2 * 3 * Copyright 2013 Felix Janda <felix.janda@posteo.de> 4 * 5 * No standard 6 7 USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN)) 8 9 config FALLOCATE 10 bool "fallocate" 11 depends on TOYBOX_FALLOCATE 12 default y 13 help 14 usage: fallocate [-l size] file 15 16 Tell the filesystem to allocate space for a file. 17 */ 18 19 #define FOR_fallocate 20 #include "toys.h" 21 GLOBALS(long size;)22GLOBALS( 23 long size; 24 ) 25 26 void fallocate_main(void) 27 { 28 int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644); 29 if (posix_fallocate(fd, 0, TT.size)) error_exit("Not enough space"); 30 if (CFG_TOYBOX_FREE) close(fd); 31 } 32