From 5ebaea605a26775186a493ed6bb401c6de7226ec Mon Sep 17 00:00:00 2001 From: Felix Janda Date: Fri, 9 Aug 2013 20:46:02 +0200 Subject: New toy: fallocate --- toys/other/fallocate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 toys/other/fallocate.c (limited to 'toys/other/fallocate.c') 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 + * + * 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); +} -- cgit v1.2.3