From e2acffe55b74ea3301b23303066df0b355947d21 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Thu, 6 Apr 2017 23:35:31 -0400 Subject: [PATCH] restructure fallocate abstraction --- src/fallocate.cpp | 2 +- ...fs_fallocate.cpp => fs_base_fallocate.cpp} | 8 ++-- ...fs_fallocate.hpp => fs_base_fallocate.hpp} | 6 +-- ...inux.icpp => fs_base_fallocate_linux.icpp} | 1 - ...te_osx.icpp => fs_base_fallocate_osx.icpp} | 46 +++++++++---------- ...osix.icpp => fs_base_fallocate_posix.icpp} | 1 - ...cpp => fs_base_fallocate_unsupported.icpp} | 1 - src/fs_clonefile.cpp | 2 +- 8 files changed, 32 insertions(+), 35 deletions(-) rename src/{fs_fallocate.cpp => fs_base_fallocate.cpp} (84%) rename src/{fs_fallocate.hpp => fs_base_fallocate.hpp} (91%) rename src/{fs_fallocate_linux.icpp => fs_base_fallocate_linux.icpp} (97%) rename src/{fs_fallocate_osx.icpp => fs_base_fallocate_osx.icpp} (69%) rename src/{fs_fallocate_posix.icpp => fs_base_fallocate_posix.icpp} (97%) rename src/{fs_fallocate_unsupported.icpp => fs_base_fallocate_unsupported.icpp} (97%) diff --git a/src/fallocate.cpp b/src/fallocate.cpp index ed1012e0..466e8f02 100644 --- a/src/fallocate.cpp +++ b/src/fallocate.cpp @@ -20,7 +20,7 @@ #include "errno.hpp" #include "fileinfo.hpp" -#include "fs_fallocate.hpp" +#include "fs_base_fallocate.hpp" static int diff --git a/src/fs_fallocate.cpp b/src/fs_base_fallocate.cpp similarity index 84% rename from src/fs_fallocate.cpp rename to src/fs_base_fallocate.cpp index 9bd15e9e..500ec090 100644 --- a/src/fs_fallocate.cpp +++ b/src/fs_base_fallocate.cpp @@ -17,11 +17,11 @@ #include #ifdef __linux__ -# include "fs_fallocate_linux.icpp" +# include "fs_base_fallocate_linux.icpp" #elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L -# include "fs_fallocate_posix.icpp" +# include "fs_base_fallocate_posix.icpp" #elif __APPLE__ -# include "fs_fallocate_osx.icpp" +# include "fs_base_fallocate_osx.icpp" #else -# include "fs_fallocate_unsupported.icpp" +# include "fs_base_fallocate_unsupported.icpp" #endif diff --git a/src/fs_fallocate.hpp b/src/fs_base_fallocate.hpp similarity index 91% rename from src/fs_fallocate.hpp rename to src/fs_base_fallocate.hpp index 074532ce..2239ae4d 100644 --- a/src/fs_fallocate.hpp +++ b/src/fs_base_fallocate.hpp @@ -14,8 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef __FS_FALLOCATE_HPP__ -#define __FS_FALLOCATE_HPP__ +#ifndef __FS_BASE_FALLOCATE_HPP__ +#define __FS_BASE_FALLOCATE_HPP__ #include @@ -28,4 +28,4 @@ namespace fs const off_t len); } -#endif // __FS_FALLOCATE_HPP__ +#endif diff --git a/src/fs_fallocate_linux.icpp b/src/fs_base_fallocate_linux.icpp similarity index 97% rename from src/fs_fallocate_linux.icpp rename to src/fs_base_fallocate_linux.icpp index 568a3a75..84e454a1 100644 --- a/src/fs_fallocate_linux.icpp +++ b/src/fs_base_fallocate_linux.icpp @@ -17,7 +17,6 @@ #include #include "errno.hpp" -#include "fs_fallocate.hpp" namespace fs { diff --git a/src/fs_fallocate_osx.icpp b/src/fs_base_fallocate_osx.icpp similarity index 69% rename from src/fs_fallocate_osx.icpp rename to src/fs_base_fallocate_osx.icpp index 70894142..ae3a06eb 100644 --- a/src/fs_fallocate_osx.icpp +++ b/src/fs_base_fallocate_osx.icpp @@ -15,34 +15,34 @@ */ #include +#include #include "errno.hpp" -#include "fs_fallocate.hpp" + +static +int +_fallocate_core(const int fd, + const off_t offset, + const off_t len) +{ + int rv; + fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0}; + + rv = ::fcntl(fd,F_PREALLOCATE,&store); + if(rv == -1) + { + store.fst_flags = F_ALLOCATEALL; + rv = ::fcntl(fd,F_PREALLOCATE,&store); + } + + if(rv == -1) + return rv; + + return ::ftruncate(fd,(offset+len)); +} namespace fs { - static - int - _fallocate_core(const int fd, - const off_t offset, - const off_t len) - { - int rv; - fstore_t store = {F_ALLOCATECONTIG,F_PEOFPOSMODE,offset,len,0}; - - rv = ::fcntl(fd,F_PREALLOCATE,&store); - if(rv == -1) - { - store.fst_flags = F_ALLOCATEALL; - rv = ::fcntl(fd,F_PREALLOCATE,&store); - } - - if(rv == -1) - return rv; - - return ::ftruncate(fd,(offset+len)); - } - int fallocate(const int fd, const int mode, diff --git a/src/fs_fallocate_posix.icpp b/src/fs_base_fallocate_posix.icpp similarity index 97% rename from src/fs_fallocate_posix.icpp rename to src/fs_base_fallocate_posix.icpp index ee14180a..4af1183e 100644 --- a/src/fs_fallocate_posix.icpp +++ b/src/fs_base_fallocate_posix.icpp @@ -17,7 +17,6 @@ #include #include "errno.hpp" -#include "fs_fallocate.hpp" namespace fs { diff --git a/src/fs_fallocate_unsupported.icpp b/src/fs_base_fallocate_unsupported.icpp similarity index 97% rename from src/fs_fallocate_unsupported.icpp rename to src/fs_base_fallocate_unsupported.icpp index f32ae0ba..e5cae483 100644 --- a/src/fs_fallocate_unsupported.icpp +++ b/src/fs_base_fallocate_unsupported.icpp @@ -15,7 +15,6 @@ */ #include "errno.hpp" -#include "fs_fallocate.hpp" namespace fs { diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index 826790b9..7628f42a 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -25,6 +25,7 @@ #include "fs_base_chmod.hpp" #include "fs_base_chown.hpp" #include "fs_base_close.hpp" +#include "fs_base_fallocate.hpp" #include "fs_base_lseek.hpp" #include "fs_base_mkdir.hpp" #include "fs_base_open.hpp" @@ -33,7 +34,6 @@ #include "fs_base_utime.hpp" #include "fs_base_write.hpp" #include "fs_fadvise.hpp" -#include "fs_fallocate.hpp" #include "fs_sendfile.hpp" #include "fs_xattr.hpp"