aboutsummaryrefslogtreecommitdiff
path: root/toys/other/fallocate.c
diff options
context:
space:
mode:
authorFelix Janda <felix.janda@posteo.de>2013-08-09 20:46:02 +0200
committerFelix Janda <felix.janda@posteo.de>2013-08-09 20:46:02 +0200
commit5ebaea605a26775186a493ed6bb401c6de7226ec (patch)
tree1d55596ab1fa998055b98adce02fef75927dff9d /toys/other/fallocate.c
parent035f27ae4df2b973b8974730bb1b23a25f6160e8 (diff)
downloadtoybox-5ebaea605a26775186a493ed6bb401c6de7226ec.tar.gz
New toy: fallocate
Diffstat (limited to 'toys/other/fallocate.c')
-rw-r--r--toys/other/fallocate.c30
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);
+}