fallocate.c 617 B

123456789101112131415161718192021222324252627282930
  1. /* fallocate.c - Preallocate space to a file
  2. *
  3. * Copyright 2013 Felix Janda <felix.janda@posteo.de>
  4. *
  5. * No standard
  6. USE_FALLOCATE(NEWTOY(fallocate, ">1l#|o#", TOYFLAG_USR|TOYFLAG_BIN))
  7. config FALLOCATE
  8. bool "fallocate"
  9. default y
  10. help
  11. usage: fallocate [-l size] [-o offset] file
  12. Tell the filesystem to allocate space for a file.
  13. */
  14. #define FOR_fallocate
  15. #include "toys.h"
  16. GLOBALS(
  17. long o, l;
  18. )
  19. void fallocate_main(void)
  20. {
  21. int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
  22. if ((errno = posix_fallocate(fd, TT.o, TT.l))) perror_exit("fallocate");
  23. if (CFG_TOYBOX_FREE) close(fd);
  24. }