From 3b66bb9066754b4980e5258f7aef642977d2e41f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 28 Nov 2020 08:39:22 +1000 Subject: [PATCH] io: add an `fallocate` wrapper --- io_posix.cpp | 2 +- posix/fd.cpp | 8 ++++++++ posix/fd.hpp | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/io_posix.cpp b/io_posix.cpp index d15dbda3..1e0dbeb3 100644 --- a/io_posix.cpp +++ b/io_posix.cpp @@ -83,7 +83,7 @@ mapped_file::~mapped_file () } -//---------------------------------------------------------------------------- +////////////////////////////////////////////////////////////////////////////// size_t mapped_file::size (void) const { diff --git a/posix/fd.cpp b/posix/fd.cpp index 115bfd93..46a945f6 100644 --- a/posix/fd.cpp +++ b/posix/fd.cpp @@ -107,6 +107,14 @@ fd::stat (void) const } +/////////////////////////////////////////////////////////////////////////////// +void +fd::allocate (int mode, off_t offset, off_t len) +{ + error::try_call (fallocate, m_fd, mode, offset, len); +} + + /////////////////////////////////////////////////////////////////////////////// void fd::close (void) diff --git a/posix/fd.hpp b/posix/fd.hpp index 1064b9b0..0babda96 100644 --- a/posix/fd.hpp +++ b/posix/fd.hpp @@ -57,6 +57,11 @@ namespace cruft::posix { struct ::stat stat (void) const; + /////////////////////////////////////////////////////////////////////// + /// A thin wrapper around `fallocate` + void allocate (int mode, off_t offset, off_t len); + + /////////////////////////////////////////////////////////////////////// void close (void); void reset (int);