• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   depends on TOYBOX_FALLOCATE
12   default y
13   help
14     usage: fallocate [-l size] [-o offset] 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 offset;long size;)22 GLOBALS(
23   long offset;
24   long size;
25 )
26 
27 void fallocate_main(void)
28 {
29   int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
30   if ((errno = posix_fallocate(fd, TT.offset, TT.size)))
31     perror_exit("fallocate");
32   if (CFG_TOYBOX_FREE) close(fd);
33 }
34