aboutsummaryrefslogtreecommitdiff
path: root/toys/other/fallocate.c
diff options
context:
space:
mode:
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);
+}