changeset 993:d5a1174ff88a

New toy: fallocate
author Felix Janda <felix.janda@posteo.de>
date Fri, 09 Aug 2013 20:46:02 +0200
parents 910f35ff76be
children 00c7b6f4104a
files toys/other/fallocate.c
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/other/fallocate.c	Fri Aug 09 20:46:02 2013 +0200
@@ -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);
+}