From 0f9fd144b79af32ad2e9d08ae4495ac6edf21b47 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 16 Aug 2013 11:14:55 +0100 Subject: [PATCH] Add fallocate(1) --- Makefile | 1 + fallocate.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 fallocate.c diff --git a/Makefile b/Makefile index 104f674..ffeb36e 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ SRC = \ clear.c \ df.c \ dmesg.c \ + fallocate.c \ free.c \ halt.c \ insmod.c \ diff --git a/fallocate.c b/fallocate.c new file mode 100644 index 0000000..b92d278 --- /dev/null +++ b/fallocate.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s -l length file\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int fd; + long size; + + ARGBEGIN { + case 'l': + size = estrtol(EARGF(usage()), 10); + break; + default: + usage(); + } ARGEND; + + if (argc != 1 || !size) + usage(); + + fd = open(argv[0], O_RDWR | O_CREAT, 0644); + if (fd < 0) + eprintf("open %s:", argv[0]); + + if (posix_fallocate(fd, 0, size) < 0) + eprintf("posix_fallocate:"); + + close(fd); + return 0; +}