aboutsummaryrefslogtreecommitdiff
path: root/toys/other/fallocate.c
blob: a73089729f2348fddda51f6ad02d357c9f157ee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* fallocate.c - Preallocate space to a file
 *
 * Copyright 2013 Felix Janda <felix.janda@posteo.de>
 *
 * No standard

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] [-o offset] file

    Tell the filesystem to allocate space for a file.
*/

#define FOR_fallocate
#include "toys.h"

GLOBALS(
  long offset;
  long size;
)

void fallocate_main(void)
{
  int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
  if ((errno = posix_fallocate(fd, TT.offset, TT.size)))
    perror_exit("fallocate");
  if (CFG_TOYBOX_FREE) close(fd);
}