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#|o#", TOYFLAG_USR|TOYFLAG_BIN))
8 
9 config FALLOCATE
10   bool "fallocate"
11   default y
12   help
13     usage: fallocate [-l size] [-o offset] file
14 
15     Tell the filesystem to allocate space for a file.
16 */
17 
18 #define FOR_fallocate
19 #include "toys.h"
20 
GLOBALS(long o,l;)21 GLOBALS(
22   long o, l;
23 )
24 
25 void fallocate_main(void)
26 {
27   int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
28   if ((errno = posix_fallocate(fd, TT.o, TT.l))) perror_exit("fallocate");
29   if (CFG_TOYBOX_FREE) close(fd);
30 }
31