annotate toys/other/fallocate.c @ 1353:2102af52be68 draft

Enable fallocate in defconfig.
author Rob Landley <rob@landley.net>
date Wed, 11 Jun 2014 22:18:35 -0500
parents d5a1174ff88a
children 5ec6582aac50
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"
1353
2102af52be68 Enable fallocate in defconfig.
Rob Landley <rob@landley.net>
parents: 993
diff changeset
11 default y
993
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
12 help
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
13 usage: fallocate [-l size] file
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
14
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
15 Tell the filesystem to allocate space for a file.
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
16 */
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 #define FOR_fallocate
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
19 #include "toys.h"
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
20
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
21 GLOBALS(
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
22 long size;
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
23 )
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 void fallocate_main(void)
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
26 {
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
27 int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
28 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
29 if (CFG_TOYBOX_FREE) close(fd);
d5a1174ff88a New toy: fallocate
Felix Janda <felix.janda@posteo.de>
parents:
diff changeset
30 }