|
|
@ -166,12 +166,12 @@ void remote_server::populate_stat(const struct stat64 &st1, remote::stat &st) {
|
|
|
|
st.st_mtimespec =
|
|
|
|
st.st_mtimespec =
|
|
|
|
st1.st_mtim.tv_nsec + (st1.st_mtim.tv_sec * NANOS_PER_SECOND);
|
|
|
|
st1.st_mtim.tv_nsec + (st1.st_mtim.tv_sec * NANOS_PER_SECOND);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
st.st_blksize = st1.st_blksize;
|
|
|
|
st.st_blksize = static_cast<remote::block_size>(st1.st_blksize);
|
|
|
|
st.st_blocks = st1.st_blocks;
|
|
|
|
st.st_blocks = static_cast<remote::block_count>(st1.st_blocks);
|
|
|
|
st.st_gid = st1.st_gid;
|
|
|
|
st.st_gid = st1.st_gid;
|
|
|
|
st.st_mode = st1.st_mode;
|
|
|
|
st.st_mode = static_cast<remote::file_mode>(st1.st_mode);
|
|
|
|
st.st_nlink = st1.st_nlink;
|
|
|
|
st.st_nlink = static_cast<remote::file_nlink>(st1.st_nlink);
|
|
|
|
st.st_size = st1.st_size;
|
|
|
|
st.st_size = static_cast<remote::file_size>(st1.st_size);
|
|
|
|
st.st_uid = st1.st_uid;
|
|
|
|
st.st_uid = st1.st_uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -227,9 +227,10 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto res =
|
|
|
|
const auto res =
|
|
|
|
open(file_path.c_str(), remote::create_os_open_flags(flags), mode);
|
|
|
|
open(file_path.c_str(),
|
|
|
|
|
|
|
|
static_cast<int>(remote::create_os_open_flags(flags)), mode);
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
handle = res;
|
|
|
|
handle = static_cast<remote::file_handle>(res);
|
|
|
|
set_open_info(res, open_info{0, "", nullptr, file_path});
|
|
|
|
set_open_info(res, open_info{0, "", nullptr, file_path});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -269,13 +270,12 @@ ConstructPath(path); auto ret = HasOpenFileInfo(handle, -EBADF); if (ret == 0) {
|
|
|
|
fstore.fst_offset = offset;
|
|
|
|
fstore.fst_offset = offset;
|
|
|
|
fstore.fst_length = length;
|
|
|
|
fstore.fst_length = length;
|
|
|
|
|
|
|
|
|
|
|
|
const auto res = fcntl(static_cast<int>(handle), F_PREALLOCATE, &fstore);
|
|
|
|
const auto res = fcntl(static_cast<native_handle>(handle), F_PREALLOCATE,
|
|
|
|
ret = ((res < 0) ? -errno : 0);
|
|
|
|
&fstore); ret = ((res < 0) ? -errno : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
const auto res = fallocate(static_cast<int>(handle), mode, offset, length);
|
|
|
|
const auto res = fallocate(static_cast<native_handle>(handle), mode, offset,
|
|
|
|
ret = ((res < 0) ? -errno : 0);
|
|
|
|
length); ret = ((res < 0) ? -errno : 0); #endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
|
|
|
@ -289,11 +289,11 @@ auto remote_server::fuse_fgetattr(const char *path, remote::stat &st,
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
memset(&st, 0, sizeof(remote::stat));
|
|
|
|
memset(&st, 0, sizeof(remote::stat));
|
|
|
|
|
|
|
|
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
directory = utils::file::is_directory(file_path);
|
|
|
|
directory = utils::file::is_directory(file_path);
|
|
|
|
struct stat64 st1 {};
|
|
|
|
struct stat64 st1 {};
|
|
|
|
if ((res = fstat64(static_cast<int>(handle), &st1)) == 0) {
|
|
|
|
if ((res = fstat64(static_cast<native_handle>(handle), &st1)) == 0) {
|
|
|
|
populate_stat(st1, st);
|
|
|
|
populate_stat(st1, st);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -314,12 +314,12 @@ auto remote_server::fuse_fsetattr_x(const char *path,
|
|
|
|
if (SETATTR_WANTS_MODE(&attr)) {
|
|
|
|
if (SETATTR_WANTS_MODE(&attr)) {
|
|
|
|
res = (handle == static_cast<std::uint64_t>(REPERTORY_INVALID_HANDLE))
|
|
|
|
res = (handle == static_cast<std::uint64_t>(REPERTORY_INVALID_HANDLE))
|
|
|
|
? chmod(file_path.c_str(), attr.mode)
|
|
|
|
? chmod(file_path.c_str(), attr.mode)
|
|
|
|
: fchmod(handle, attr.mode);
|
|
|
|
: fchmod(static_cast<native_handle>(handle), attr.mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
uid_t uid = -1;
|
|
|
|
auto uid = static_cast<uid_t>(-1);
|
|
|
|
gid_t gid = -1;
|
|
|
|
auto gid = static_cast<gid_t>(-1);
|
|
|
|
if (SETATTR_WANTS_UID(&attr)) {
|
|
|
|
if (SETATTR_WANTS_UID(&attr)) {
|
|
|
|
uid = attr.uid;
|
|
|
|
uid = attr.uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -338,7 +338,7 @@ auto remote_server::fuse_fsetattr_x(const char *path,
|
|
|
|
if (SETATTR_WANTS_SIZE(&attr)) {
|
|
|
|
if (SETATTR_WANTS_SIZE(&attr)) {
|
|
|
|
res = (handle == static_cast<std::uint64_t>(REPERTORY_INVALID_HANDLE))
|
|
|
|
res = (handle == static_cast<std::uint64_t>(REPERTORY_INVALID_HANDLE))
|
|
|
|
? truncate(file_path.c_str(), attr.size)
|
|
|
|
? truncate(file_path.c_str(), attr.size)
|
|
|
|
: ftruncate(handle, attr.size);
|
|
|
|
: ftruncate(static_cast<native_handle>(handle), attr.size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -397,14 +397,14 @@ auto remote_server::fuse_fsync(const char *path, const std::int32_t &datasync,
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
|
|
|
|
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#ifdef __APPLE__
|
|
|
|
res = datasync ? fcntl(static_cast<int>(handle), F_FULLFSYNC)
|
|
|
|
res = datasync ? fcntl(static_cast<native_handle>(handle), F_FULLFSYNC)
|
|
|
|
: fsync(static_cast<int>(handle));
|
|
|
|
: fsync(static_cast<native_handle>(handle));
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
res = datasync ? fdatasync(static_cast<int>(handle))
|
|
|
|
res = datasync ? fdatasync(static_cast<native_handle>(handle))
|
|
|
|
: fsync(static_cast<int>(handle));
|
|
|
|
: fsync(static_cast<native_handle>(handle));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -419,9 +419,9 @@ auto remote_server::fuse_ftruncate(const char *path,
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
|
|
|
|
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
res = ftruncate(static_cast<int>(handle), size);
|
|
|
|
res = ftruncate(static_cast<native_handle>(handle), size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto ret = ((res < 0) ? -errno : 0);
|
|
|
|
auto ret = ((res < 0) ? -errno : 0);
|
|
|
@ -472,7 +472,7 @@ utils::path::get_parent_api_path(api_path);
|
|
|
|
res = -ENODATA;
|
|
|
|
res = -ENODATA;
|
|
|
|
if (directoryItem.MetaMap.find(name) != directoryItem.MetaMap.end())
|
|
|
|
if (directoryItem.MetaMap.find(name) != directoryItem.MetaMap.end())
|
|
|
|
{ const auto data = macaron::Base64::Decode(directoryItem.MetaMap[name]); res =
|
|
|
|
{ const auto data = macaron::Base64::Decode(directoryItem.MetaMap[name]); res =
|
|
|
|
static_cast<int>(data.size()); if (size) { res = -ERANGE; if (size >=
|
|
|
|
static_cast<native_handle>(data.size()); if (size) { res = -ERANGE; if (size >=
|
|
|
|
data.size()) { memcpy(value, &data[0], data.size()); res = 0;
|
|
|
|
data.size()) { memcpy(value, &data[0], data.size()); res = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -561,9 +561,10 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
|
|
|
|
remote::file_handle &handle)
|
|
|
|
remote::file_handle &handle)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto res = open(file_path.c_str(), remote::create_os_open_flags(flags));
|
|
|
|
const auto res = open(file_path.c_str(),
|
|
|
|
|
|
|
|
static_cast<int>(remote::create_os_open_flags(flags)));
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
handle = res;
|
|
|
|
handle = static_cast<remote::file_handle>(res);
|
|
|
|
set_open_info(res, open_info{0, "", nullptr, file_path});
|
|
|
|
set_open_info(res, open_info{0, "", nullptr, file_path});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto ret = ((res < 0) ? -errno : 0);
|
|
|
|
auto ret = ((res < 0) ? -errno : 0);
|
|
|
@ -601,10 +602,11 @@ auto remote_server::fuse_read(const char *path, char *buffer,
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
auto &b = *reinterpret_cast<data_buffer *>(buffer);
|
|
|
|
auto &b = *reinterpret_cast<data_buffer *>(buffer);
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
b.resize(read_size);
|
|
|
|
b.resize(read_size);
|
|
|
|
res = pread64(static_cast<int>(handle), &b[0], read_size, read_offset);
|
|
|
|
res = pread64(static_cast<native_handle>(handle), &b[0], read_size,
|
|
|
|
|
|
|
|
read_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto ret = ((res < 0) ? -errno : res);
|
|
|
|
auto ret = ((res < 0) ? -errno : res);
|
|
|
@ -655,10 +657,10 @@ auto remote_server::fuse_release(const char *path,
|
|
|
|
packet::error_type ret = 0;
|
|
|
|
packet::error_type ret = 0;
|
|
|
|
|
|
|
|
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
res = close(static_cast<int>(handle));
|
|
|
|
res = close(static_cast<native_handle>(handle));
|
|
|
|
remove_open_info(handle);
|
|
|
|
remove_open_info(static_cast<native_handle>(handle));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret = ((res < 0) ? -errno : 0);
|
|
|
|
ret = ((res < 0) ? -errno : 0);
|
|
|
@ -890,9 +892,10 @@ auto remote_server::fuse_write(const char *path, const char *buffer,
|
|
|
|
const remote::file_handle &handle)
|
|
|
|
const remote::file_handle &handle)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
const auto file_path = construct_path(path);
|
|
|
|
auto res = has_open_info(handle, EBADF);
|
|
|
|
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
|
|
|
if (res == 0) {
|
|
|
|
if (res == 0) {
|
|
|
|
res = pwrite64(static_cast<int>(handle), buffer, write_size, write_offset);
|
|
|
|
res = pwrite64(static_cast<native_handle>(handle), buffer, write_size,
|
|
|
|
|
|
|
|
write_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto ret = ((res < 0) ? -errno : res);
|
|
|
|
auto ret = ((res < 0) ? -errno : res);
|
|
|
@ -916,8 +919,10 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto relative_path = utils::string::to_utf8(file_name);
|
|
|
|
const auto relative_path = utils::string::to_utf8(file_name);
|
|
|
|
const auto file_path = construct_path(relative_path);
|
|
|
|
const auto file_path = construct_path(relative_path);
|
|
|
|
auto ret = has_open_info(reinterpret_cast<remote::file_handle>(file_desc),
|
|
|
|
auto ret =
|
|
|
|
STATUS_INVALID_HANDLE);
|
|
|
|
has_open_info(static_cast<native_handle>(
|
|
|
|
|
|
|
|
reinterpret_cast<remote::file_handle>(file_desc)),
|
|
|
|
|
|
|
|
STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
ret =
|
|
|
|
ret =
|
|
|
|
utils::file::is_directory(file_path)
|
|
|
|
utils::file::is_directory(file_path)
|
|
|
@ -994,10 +999,11 @@ auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
|
|
|
|
auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
|
|
|
|
auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
|
|
|
|
std::string file_path;
|
|
|
|
std::string file_path;
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) {
|
|
|
|
if (has_open_info(static_cast<native_handle>(handle),
|
|
|
|
file_path = get_open_file_path(handle);
|
|
|
|
STATUS_INVALID_HANDLE) == STATUS_SUCCESS) {
|
|
|
|
close(handle);
|
|
|
|
file_path = get_open_file_path(static_cast<native_handle>(handle));
|
|
|
|
remove_open_info(handle);
|
|
|
|
close(static_cast<native_handle>(handle));
|
|
|
|
|
|
|
|
remove_open_info(static_cast<native_handle>(handle));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, STATUS_SUCCESS);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, STATUS_SUCCESS);
|
|
|
@ -1056,15 +1062,19 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
|
|
|
|
auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
|
|
|
|
auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
ret = (fsync(static_cast<int>(handle)) < 0)
|
|
|
|
ret = (fsync(static_cast<native_handle>(handle)) < 0)
|
|
|
|
? utils::unix_error_to_windows(errno)
|
|
|
|
? utils::unix_error_to_windows(errno)
|
|
|
|
: populate_file_info(
|
|
|
|
: populate_file_info(construct_api_path(get_open_file_path(
|
|
|
|
construct_api_path(get_open_file_path(handle)), *file_info);
|
|
|
|
static_cast<native_handle>(handle))),
|
|
|
|
|
|
|
|
*file_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1072,13 +1082,17 @@ auto remote_server::winfsp_get_file_info(PVOID file_desc,
|
|
|
|
remote::file_info *file_info)
|
|
|
|
remote::file_info *file_info)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(
|
|
|
|
|
|
|
|
static_cast<native_handle>(handle))),
|
|
|
|
*file_info);
|
|
|
|
*file_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1163,10 +1177,12 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
|
|
|
remote::file_info *file_info)
|
|
|
|
remote::file_info *file_info)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto api_path = construct_api_path(get_open_file_path(handle));
|
|
|
|
const auto api_path = construct_api_path(
|
|
|
|
const auto res = ftruncate(handle, 0);
|
|
|
|
get_open_file_path(static_cast<native_handle>(handle)));
|
|
|
|
|
|
|
|
const auto res = ftruncate(static_cast<native_handle>(handle), 0);
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
auto set_attributes = false;
|
|
|
|
auto set_attributes = false;
|
|
|
|
if (replace_attributes) {
|
|
|
|
if (replace_attributes) {
|
|
|
@ -1195,14 +1211,17 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
|
|
|
drive_.set_item_meta(api_path, META_ATTRIBUTES,
|
|
|
|
drive_.set_item_meta(api_path, META_ATTRIBUTES,
|
|
|
|
std::to_string(attributes));
|
|
|
|
std::to_string(attributes));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(
|
|
|
|
|
|
|
|
static_cast<native_handle>(handle))),
|
|
|
|
*file_info);
|
|
|
|
*file_info);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1212,17 +1231,20 @@ auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
|
|
|
|
*bytes_transferred = 0;
|
|
|
|
*bytes_transferred = 0;
|
|
|
|
|
|
|
|
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto res = pread64(handle, buffer, length, offset);
|
|
|
|
const auto res = pread64(handle, buffer, length, offset);
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
*bytes_transferred = res;
|
|
|
|
*bytes_transferred = static_cast<UINT32>(res);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1232,9 +1254,11 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
|
|
|
|
item_list.clear();
|
|
|
|
item_list.clear();
|
|
|
|
|
|
|
|
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto api_path = construct_api_path(get_open_file_path(handle));
|
|
|
|
const auto api_path = construct_api_path(
|
|
|
|
|
|
|
|
get_open_file_path(static_cast<native_handle>(handle)));
|
|
|
|
auto list = drive_.get_directory_items(api_path);
|
|
|
|
auto list = drive_.get_directory_items(api_path);
|
|
|
|
directory_iterator iterator(std::move(list));
|
|
|
|
directory_iterator iterator(std::move(list));
|
|
|
|
auto offset = marker
|
|
|
|
auto offset = marker
|
|
|
@ -1253,7 +1277,9 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1288,9 +1314,11 @@ auto remote_server::winfsp_set_basic_info(
|
|
|
|
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
|
|
|
|
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
|
|
|
|
remote::file_info *file_info) -> packet::error_type {
|
|
|
|
remote::file_info *file_info) -> packet::error_type {
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto file_path = get_open_file_path(handle);
|
|
|
|
const auto file_path =
|
|
|
|
|
|
|
|
get_open_file_path(static_cast<native_handle>(handle));
|
|
|
|
if (attributes == INVALID_FILE_ATTRIBUTES) {
|
|
|
|
if (attributes == INVALID_FILE_ATTRIBUTES) {
|
|
|
|
attributes = 0;
|
|
|
|
attributes = 0;
|
|
|
|
} else if (attributes == 0) {
|
|
|
|
} else if (attributes == 0) {
|
|
|
@ -1337,7 +1365,9 @@ auto remote_server::winfsp_set_basic_info(
|
|
|
|
ret = populate_file_info(api_path, *file_info);
|
|
|
|
ret = populate_file_info(api_path, *file_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1346,17 +1376,24 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
|
|
|
|
remote::file_info *file_info)
|
|
|
|
remote::file_info *file_info)
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto res = set_allocation_size ? 0 : ftruncate(handle, new_size);
|
|
|
|
const auto res =
|
|
|
|
|
|
|
|
set_allocation_size
|
|
|
|
|
|
|
|
? 0
|
|
|
|
|
|
|
|
: ftruncate(static_cast<native_handle>(handle), new_size);
|
|
|
|
ret = ((res < 0) ? utils::unix_error_to_windows(errno) : 0);
|
|
|
|
ret = ((res < 0) ? utils::unix_error_to_windows(errno) : 0);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(
|
|
|
|
|
|
|
|
static_cast<native_handle>(handle))),
|
|
|
|
*file_info);
|
|
|
|
*file_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1375,9 +1412,11 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
|
|
|
|
-> packet::error_type {
|
|
|
|
-> packet::error_type {
|
|
|
|
*bytes_transferred = 0;
|
|
|
|
*bytes_transferred = 0;
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
|
|
|
|
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
|
|
|
|
auto ret =
|
|
|
|
|
|
|
|
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
if (ret == STATUS_SUCCESS) {
|
|
|
|
const auto api_path = construct_api_path(get_open_file_path(handle));
|
|
|
|
const auto api_path = construct_api_path(
|
|
|
|
|
|
|
|
get_open_file_path(static_cast<native_handle>(handle)));
|
|
|
|
const auto file_size = drive_.get_file_size(api_path);
|
|
|
|
const auto file_size = drive_.get_file_size(api_path);
|
|
|
|
if (write_to_end) {
|
|
|
|
if (write_to_end) {
|
|
|
|
offset = file_size;
|
|
|
|
offset = file_size;
|
|
|
@ -1389,7 +1428,7 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
should_write = false;
|
|
|
|
should_write = false;
|
|
|
|
} else if ((offset + length) > file_size) {
|
|
|
|
} else if ((offset + length) > file_size) {
|
|
|
|
length = static_cast<UINT64>(file_size - offset);
|
|
|
|
length = static_cast<UINT32>(file_size - offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1397,9 +1436,10 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
|
|
|
|
if (length > 0) {
|
|
|
|
if (length > 0) {
|
|
|
|
const auto res = pwrite64(handle, buffer, length, offset);
|
|
|
|
const auto res = pwrite64(handle, buffer, length, offset);
|
|
|
|
if (res >= 0) {
|
|
|
|
if (res >= 0) {
|
|
|
|
*bytes_transferred = res;
|
|
|
|
*bytes_transferred = static_cast<UINT32>(res);
|
|
|
|
ret = populate_file_info(
|
|
|
|
ret = populate_file_info(construct_api_path(get_open_file_path(
|
|
|
|
construct_api_path(get_open_file_path(handle)), *file_info);
|
|
|
|
static_cast<native_handle>(handle))),
|
|
|
|
|
|
|
|
*file_info);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
ret = utils::unix_error_to_windows(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1407,7 +1447,9 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, get_open_file_path(handle), ret);
|
|
|
|
RAISE_REMOTE_FUSE_SERVER_EVENT(
|
|
|
|
|
|
|
|
__FUNCTION__, get_open_file_path(static_cast<native_handle>(handle)),
|
|
|
|
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|