From a470ee6f93e94493d402d61b4d6e4c2cd91424e4 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 25 Jun 2023 07:21:35 +0800 Subject: [PATCH] Fix mmap block device --- native/src/base/files.hpp | 3 +++ native/src/base/files.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/native/src/base/files.hpp b/native/src/base/files.hpp index 4610ffc29..0d8d11caf 100644 --- a/native/src/base/files.hpp +++ b/native/src/base/files.hpp @@ -6,6 +6,7 @@ #include #include +#include #include "misc.hpp" template @@ -42,6 +43,8 @@ struct mount_info { }; struct mmap_data : public byte_data { + static_assert((sizeof(void *) == 8 && BLKGETSIZE64 == 0x80081272) || + (sizeof(void *) == 4 && BLKGETSIZE64 == 0x80041272)); ALLOW_MOVE_ONLY(mmap_data) explicit mmap_data(const char *name, bool rw = false); diff --git a/native/src/base/files.rs b/native/src/base/files.rs index 59b12fc2d..521094577 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -483,8 +483,12 @@ pub(crate) fn map_file(path: &Utf8CStr, rw: bool) -> io::Result<&'static mut [u8 fn ioctl(fd: RawFd, request: u32, ...) -> i32; } + #[cfg(target_pointer_width = "64")] const BLKGETSIZE64: u32 = 0x80081272; + #[cfg(target_pointer_width = "32")] + const BLKGETSIZE64: u32 = 0x80041272; + let flag = if rw { O_RDWR } else { O_RDONLY }; let f = File::from(open_fd!(path, flag | O_CLOEXEC)?);