Skip to content

Commit

Permalink
Merge pull request trapexit#391 from trapexit/fallocate
Browse files Browse the repository at this point in the history
restructure fallocate abstraction
  • Loading branch information
trapexit authored Apr 7, 2017
2 parents 998966e + e2acffe commit 581356a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/fallocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_fallocate.hpp"
#include "fs_base_fallocate.hpp"

static
int
Expand Down
8 changes: 4 additions & 4 deletions src/fs_fallocate.cpp → src/fs_base_fallocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <fcntl.h>

#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
6 changes: 3 additions & 3 deletions src/fs_fallocate.hpp → src/fs_base_fallocate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>

Expand All @@ -28,4 +28,4 @@ namespace fs
const off_t len);
}

#endif // __FS_FALLOCATE_HPP__
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <fcntl.h>

#include "errno.hpp"
#include "fs_fallocate.hpp"

namespace fs
{
Expand Down
40 changes: 20 additions & 20 deletions src/fs_fallocate_osx.icpp → src/fs_base_fallocate_osx.icpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@
*/

#include <fcntl.h>
#include <unistd.h>

#include "errno.hpp"
#include "fs_fallocate.hpp"

namespace fs
static
int
_fallocate_core(const int fd,
const off_t offset,
const off_t len)
{
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};
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);
}
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;
if(rv == -1)
return rv;

return ::ftruncate(fd,(offset+len));
}
return ::ftruncate(fd,(offset+len));
}

namespace fs
{
int
fallocate(const int fd,
const int mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <fcntl.h>

#include "errno.hpp"
#include "fs_fallocate.hpp"

namespace fs
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "errno.hpp"
#include "fs_fallocate.hpp"

namespace fs
{
Expand Down
2 changes: 1 addition & 1 deletion src/fs_clonefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down

0 comments on commit 581356a

Please sign in to comment.