fixes
This commit is contained in:
parent
5fcc59434b
commit
158cd55b1a
@ -1088,32 +1088,33 @@ auto winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
std::string api_path;
|
||||
auto error = api_error::invalid_handle;
|
||||
std::shared_ptr<i_open_file> file;
|
||||
const auto handle_error = [this, &api_path, &file,
|
||||
&file_info](auto error) -> NTSTATUS {
|
||||
auto ret = utils::from_api_error(error);
|
||||
RAISE_WINFSP_EVENT(function_name, api_path, ret);
|
||||
|
||||
if (file_info != nullptr && file && error == api_error::success) {
|
||||
// Populate file information
|
||||
api_meta_map meta;
|
||||
if (provider_.get_item_meta(api_path, meta) == api_error::success) {
|
||||
populate_file_info(file->get_file_size(), meta, *file_info);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
auto handle =
|
||||
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
|
||||
if (handle != 0U) {
|
||||
std::shared_ptr<i_open_file> file;
|
||||
if (fm_->get_open_file(handle, true, file)) {
|
||||
api_path = file->get_api_path();
|
||||
if (set_allocation_size != 0U) {
|
||||
const auto allocator = [&](native_handle cur_handle) -> api_error {
|
||||
std::string meta_allocation_size;
|
||||
utils::calculate_allocation_size(false, 0, new_size,
|
||||
meta_allocation_size);
|
||||
if (handle == 0U || not fm_->get_open_file(handle, true, file)) {
|
||||
return handle_error(api_error::invalid_handle);
|
||||
}
|
||||
|
||||
FILE_ALLOCATION_INFO allocation_info{};
|
||||
allocation_info.AllocationSize.QuadPart =
|
||||
static_cast<LONGLONG>(new_size);
|
||||
return ::SetFileInformationByHandle(cur_handle, FileAllocationInfo,
|
||||
&allocation_info,
|
||||
sizeof(allocation_info)) != 0
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
};
|
||||
|
||||
error = file->native_operation(allocator);
|
||||
} else {
|
||||
const auto allocator = [&](native_handle cur_handle) -> api_error {
|
||||
api_path = file->get_api_path();
|
||||
if (set_allocation_size == 0U) {
|
||||
return handle_error(file->native_operation(
|
||||
new_size, [&](native_handle cur_handle) -> api_error {
|
||||
FILE_END_OF_FILE_INFO end_of_file_info{};
|
||||
end_of_file_info.EndOfFile.QuadPart = static_cast<LONGLONG>(new_size);
|
||||
return ::SetFileInformationByHandle(cur_handle, FileEndOfFileInfo,
|
||||
@ -1121,23 +1122,24 @@ auto winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
|
||||
sizeof(end_of_file_info)) != 0
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
};
|
||||
error = file->native_operation(new_size, allocator);
|
||||
}
|
||||
|
||||
if (file_info != nullptr) {
|
||||
// Populate file information
|
||||
api_meta_map meta;
|
||||
if (provider_.get_item_meta(api_path, meta) == api_error::success) {
|
||||
populate_file_info(file->get_file_size(), meta, *file_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
auto ret = utils::from_api_error(error);
|
||||
RAISE_WINFSP_EVENT(function_name, api_path, ret);
|
||||
return ret;
|
||||
return handle_error(
|
||||
file->native_operation([&](native_handle cur_handle) -> api_error {
|
||||
std::string meta_allocation_size;
|
||||
utils::calculate_allocation_size(false, 0, new_size,
|
||||
meta_allocation_size);
|
||||
|
||||
FILE_ALLOCATION_INFO allocation_info{};
|
||||
allocation_info.AllocationSize.QuadPart =
|
||||
static_cast<LONGLONG>(new_size);
|
||||
return ::SetFileInformationByHandle(cur_handle, FileAllocationInfo,
|
||||
&allocation_info,
|
||||
sizeof(allocation_info)) == 0
|
||||
? api_error::os_error
|
||||
: api_error::success;
|
||||
}));
|
||||
}
|
||||
|
||||
VOID winfsp_drive::Unmounted(PVOID host) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user