annotate toys/other/fallocate.c @ 1369:5ec6582aac50 draft

Make fallocate depend on probe for libc support.
author Rob Landley <rob@landley.net>
date Sat, 28 Jun 2014 22:17:00 -0500
parents 2102af52be68
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
993
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
1 /* fallocate.c - Preallocate space to a file
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
2 *
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
3 * Copyright 2013 Felix Janda <felix.janda@posteo.de>
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
4 *
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
5 * No standard
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
6
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
7 USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN))
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
8
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
9 config FALLOCATE
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
10 bool "fallocate"
1369
5ec6582aac50 Make fallocate depend on probe for libc support.
Rob Landley <rob@landley.net>
parents: 1353
diff changeset
11 depends on TOYBOX_FALLOCATE
1353
2102af52be68 Enable fallocate in defconfig.
Rob Landley <rob@landley.net>
parents: 993
diff changeset
12 default y
993
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
13 help
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
14 usage: fallocate [-l size] file
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
15
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
16 Tell the filesystem to allocate space for a file.
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
17 */
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
18
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
19 #define FOR_fallocate
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
20 #include "toys.h"
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
21
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
22 GLOBALS(
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
23 long size;
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
24 )
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
25
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
26 void fallocate_main(void)
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
27 {
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
28 int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
29 if (posix_fallocate(fd, 0, TT.size)) error_exit("Not enough space");
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
30 if (CFG_TOYBOX_FREE) close(fd);
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
31 }