From 31c519dcd7fba4291adfdb9f0d273929cdab7eb4 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 25 Oct 2016 15:51:05 -0700 Subject: Add fallocate -o. Also improve error reporting. --- toys/other/fallocate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/toys/other/fallocate.c b/toys/other/fallocate.c index 7a226343..a7308972 100644 --- a/toys/other/fallocate.c +++ b/toys/other/fallocate.c @@ -4,14 +4,14 @@ * * No standard -USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN)) +USE_FALLOCATE(NEWTOY(fallocate, ">1l#|o#", TOYFLAG_USR|TOYFLAG_BIN)) config FALLOCATE bool "fallocate" depends on TOYBOX_FALLOCATE default y help - usage: fallocate [-l size] file + usage: fallocate [-l size] [-o offset] file Tell the filesystem to allocate space for a file. */ @@ -20,12 +20,14 @@ config FALLOCATE #include "toys.h" GLOBALS( + long offset; 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 ((errno = posix_fallocate(fd, TT.offset, TT.size))) + perror_exit("fallocate"); if (CFG_TOYBOX_FREE) close(fd); } -- cgit v1.2.3