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