mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 16:06:27 -05:00
fix short writes on >2GB files when cloning file
This commit is contained in:
parent
026dc5f750
commit
4d82ed9324
8 changed files with 286 additions and 212 deletions
67
src/fs_copydata_copy_file_range.cpp
Normal file
67
src/fs_copydata_copy_file_range.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_copy_file_range.hpp"
|
||||
|
||||
namespace l
|
||||
{
|
||||
int64_t
|
||||
copydata_copy_file_range(const int src_fd_,
|
||||
const int dst_fd_,
|
||||
uint64_t size_)
|
||||
{
|
||||
int64_t rv;
|
||||
uint64_t len;
|
||||
int64_t src_off;
|
||||
int64_t dst_off;
|
||||
|
||||
src_off = 0;
|
||||
dst_off = 0;
|
||||
len = size_;
|
||||
do
|
||||
{
|
||||
rv = fs::copy_file_range(src_fd_,&src_off,dst_fd_,&dst_off,len,0);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
len -= rv;
|
||||
}
|
||||
while((len > 0) && (rv > 0));
|
||||
|
||||
return size_;
|
||||
}
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int64_t
|
||||
copydata_copy_file_range(const int src_fd_,
|
||||
const int dst_fd_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
rv = fs::fstat(src_fd_,&st);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
return l::copydata_copy_file_range(src_fd_,
|
||||
dst_fd_,
|
||||
st.st_size);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue