Felix Janda | 5ebaea6 | 2013-08-09 20:46:02 +0200 | [diff] [blame] | 1 | /* fallocate.c - Preallocate space to a file |
| 2 | * |
| 3 | * Copyright 2013 Felix Janda <felix.janda@posteo.de> |
| 4 | * |
| 5 | * No standard |
| 6 | |
| 7 | USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN)) |
| 8 | |
| 9 | config FALLOCATE |
| 10 | bool "fallocate" |
Rob Landley | eb3c443 | 2014-06-11 22:18:35 -0500 | [diff] [blame^] | 11 | default y |
Felix Janda | 5ebaea6 | 2013-08-09 20:46:02 +0200 | [diff] [blame] | 12 | help |
| 13 | usage: fallocate [-l size] file |
| 14 | |
| 15 | Tell the filesystem to allocate space for a file. |
| 16 | */ |
| 17 | |
| 18 | #define FOR_fallocate |
| 19 | #include "toys.h" |
| 20 | |
| 21 | GLOBALS( |
| 22 | long size; |
| 23 | ) |
| 24 | |
| 25 | void fallocate_main(void) |
| 26 | { |
| 27 | int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644); |
| 28 | if (posix_fallocate(fd, 0, TT.size)) error_exit("Not enough space"); |
| 29 | if (CFG_TOYBOX_FREE) close(fd); |
| 30 | } |