10f66f451Sopenharmony_ci/* fallocate.c - Preallocate space to a file
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2013 Felix Janda <felix.janda@posteo.de>
40f66f451Sopenharmony_ci *
50f66f451Sopenharmony_ci * No standard
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ciUSE_FALLOCATE(NEWTOY(fallocate, ">1l#|o#", TOYFLAG_USR|TOYFLAG_BIN))
80f66f451Sopenharmony_ci
90f66f451Sopenharmony_ciconfig FALLOCATE
100f66f451Sopenharmony_ci  bool "fallocate"
110f66f451Sopenharmony_ci  depends on TOYBOX_FALLOCATE
120f66f451Sopenharmony_ci  default y
130f66f451Sopenharmony_ci  help
140f66f451Sopenharmony_ci    usage: fallocate [-l size] [-o offset] file
150f66f451Sopenharmony_ci
160f66f451Sopenharmony_ci    Tell the filesystem to allocate space for a file.
170f66f451Sopenharmony_ci*/
180f66f451Sopenharmony_ci
190f66f451Sopenharmony_ci#define FOR_fallocate
200f66f451Sopenharmony_ci#include "toys.h"
210f66f451Sopenharmony_ci
220f66f451Sopenharmony_ciGLOBALS(
230f66f451Sopenharmony_ci  long o, l;
240f66f451Sopenharmony_ci)
250f66f451Sopenharmony_ci
260f66f451Sopenharmony_civoid fallocate_main(void)
270f66f451Sopenharmony_ci{
280f66f451Sopenharmony_ci  int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
290f66f451Sopenharmony_ci  if ((errno = posix_fallocate(fd, TT.o, TT.l))) perror_exit("fallocate");
300f66f451Sopenharmony_ci  if (CFG_TOYBOX_FREE) close(fd);
310f66f451Sopenharmony_ci}
32