Address compiler warnings #10 [Wconversion]

This commit is contained in:
Scott E. Graves 2023-10-30 11:41:45 -05:00
parent e9b202f5c8
commit 383c3b4be6
3 changed files with 66 additions and 52 deletions

View File

@ -912,7 +912,7 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
res = api_error::xattr_buffer_small; res = api_error::xattr_buffer_small;
} }
required_size += attribute_name_size; required_size += static_cast<int>(attribute_name_size);
#ifdef __APPLE__ #ifdef __APPLE__
} }
#endif #endif

View File

@ -60,8 +60,8 @@ auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode,
auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode) auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode)
-> api_error { -> api_error {
#endif #endif
return utils::to_api_error( return utils::to_api_error(remote_instance_->fuse_chmod(
remote_instance_->fuse_chmod(api_path.c_str(), mode)); api_path.c_str(), static_cast<remote::file_mode>(mode)));
} }
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
@ -79,7 +79,9 @@ auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode, auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi) -> api_error { struct fuse_file_info *fi) -> api_error {
return utils::to_api_error(remote_instance_->fuse_create( return utils::to_api_error(remote_instance_->fuse_create(
api_path.c_str(), mode, remote::create_open_flags(fi->flags), fi->fh)); api_path.c_str(), static_cast<remote::file_mode>(mode),
remote::create_open_flags(static_cast<std::uint32_t>(fi->flags)),
fi->fh));
} }
void remote_fuse_drive::destroy_impl(void * /*ptr*/) { void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
@ -248,8 +250,8 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
auto remote_fuse_drive::mkdir_impl(std::string api_path, mode_t mode) auto remote_fuse_drive::mkdir_impl(std::string api_path, mode_t mode)
-> api_error { -> api_error {
return utils::to_api_error( return utils::to_api_error(remote_instance_->fuse_mkdir(
remote_instance_->fuse_mkdir(api_path.c_str(), mode)); api_path.c_str(), static_cast<remote::file_mode>(mode)));
} }
void remote_fuse_drive::notify_fuse_main_exit(int &ret) { void remote_fuse_drive::notify_fuse_main_exit(int &ret) {

View File

@ -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;
} }
@ -269,13 +269,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 +288,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 +313,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 +337,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 +396,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 +418,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 +471,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;
} }
} }
@ -601,10 +600,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 +655,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 +890,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);
@ -994,10 +995,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 +1058,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 +1078,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 +1173,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) {