diff options
author | Felix Janda <felix.janda@posteo.de> | 2013-08-09 20:46:02 +0200 |
---|---|---|
committer | Felix Janda <felix.janda@posteo.de> | 2013-08-09 20:46:02 +0200 |
commit | 5ebaea605a26775186a493ed6bb401c6de7226ec (patch) | |
tree | 1d55596ab1fa998055b98adce02fef75927dff9d /toys | |
parent | 035f27ae4df2b973b8974730bb1b23a25f6160e8 (diff) | |
download | toybox-5ebaea605a26775186a493ed6bb401c6de7226ec.tar.gz |
New toy: fallocate
Diffstat (limited to 'toys')
-rw-r--r-- | toys/other/fallocate.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/toys/other/fallocate.c b/toys/other/fallocate.c new file mode 100644 index 00000000..22ef978d --- /dev/null +++ b/toys/other/fallocate.c @@ -0,0 +1,30 @@ +/* fallocate.c - Preallocate space to a file + * + * Copyright 2013 Felix Janda <felix.janda@posteo.de> + * + * No standard + +USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN)) + +config FALLOCATE + bool "fallocate" + default n + help + usage: fallocate [-l size] file + + Tell the filesystem to allocate space for a file. +*/ + +#define FOR_fallocate +#include "toys.h" + +GLOBALS( + long size; +) + +void fallocate_main(void) +{ + int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644); + if (posix_fallocate(fd, 0, TT.size)) error_exit("Not enough space"); + if (CFG_TOYBOX_FREE) close(fd); +} |