diff --git a/proprietary/DiskImage/Disk/Linux.cs b/proprietary/DiskImage/Disk/Linux.cs index b7c0100e5..5f2fa8f0c 100644 --- a/proprietary/DiskImage/Disk/Linux.cs +++ b/proprietary/DiskImage/Disk/Linux.cs @@ -41,11 +41,13 @@ namespace Duplicati.Proprietary.DiskImage.Disk // File open flags from private const int O_RDONLY = 0x0000; private const int O_RDWR = 0x0002; - // TODO Should be processor architecture agnostic. // O_DIRECT: bypass kernel page cache for unbuffered I/O - // Value is architecture-dependent: 0x4000 on x86_64, 0x10000 on aarch64 - // Using 0x4000 as the most common value (x86_64) - private const int O_DIRECT = 0x4000; + // Value is architecture-dependent: 0x4000 on x86/x86_64/arm32, 0x10000 on arm64 + private static int O_DIRECT => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) switch + { + true when RuntimeInformation.OSArchitecture == Architecture.Arm64 => 0x10000, + _ => 0x4000 // Default to x86/x86_64/arm32 value + }; private readonly string m_devicePath; private int m_fileDescriptor = -1; @@ -484,6 +486,8 @@ namespace Duplicati.Proprietary.DiskImage.Disk #region P/Invoke Declarations // P/Invoke to the native wrapper library for ioctls + // The .NET runtime will automatically load the correct architecture-specific version + // from runtimes/linux-{arch}/native/libc_wrapper.so based on the current RID [LibraryImport("libc_wrapper.so", SetLastError = true)] internal static partial int ioctl_uint32(int fd, uint request, ref uint value); diff --git a/proprietary/DiskImage/Duplicati.Proprietary.DiskImage.csproj b/proprietary/DiskImage/Duplicati.Proprietary.DiskImage.csproj index 470c66803..7b3bb2489 100644 --- a/proprietary/DiskImage/Duplicati.Proprietary.DiskImage.csproj +++ b/proprietary/DiskImage/Duplicati.Proprietary.DiskImage.csproj @@ -16,26 +16,35 @@ + + + PreserveNewest runtimes/osx/native/libSystem_wrapper.dylib - - - - - - - - - - - + + PreserveNewest - libc_wrapper.so + runtimes/linux-x86/native/libc_wrapper.so + + + + PreserveNewest + runtimes/linux-x64/native/libc_wrapper.so + + + + PreserveNewest + runtimes/linux-arm/native/libc_wrapper.so + + + + PreserveNewest + runtimes/linux-arm64/native/libc_wrapper.so diff --git a/proprietary/DiskImage/NativeLibraryWrappers/compile_linux.sh b/proprietary/DiskImage/NativeLibraryWrappers/compile_linux.sh new file mode 100755 index 000000000..4f60a051d --- /dev/null +++ b/proprietary/DiskImage/NativeLibraryWrappers/compile_linux.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +# Compile Linux libc wrapper for multiple architectures +# Note: Unlike macOS, Linux does not support creating a single multi-arch .so file via standard tools. +# This script creates separate .so files for each architecture. + +# First, check if docker is available on PATH +if ! command -v docker &> /dev/null +then + echo "Docker is not installed. Please install Docker to continue." + exit 1 +fi + +echo "Compiling x86..." +docker run --rm dockcross/linux-x86 > dockcross && chmod +x dockcross +./dockcross /bin/bash -c '$CC -shared -fPIC -m32 -o libc_wrapper_x86.so linux_libc_wrapper.c' + +echo "Compiling x64..." +docker run --rm dockcross/linux-x64 > dockcross && chmod +x dockcross +./dockcross /bin/bash -c '$CC -shared -fPIC -m64 -o libc_wrapper_x86_64.so linux_libc_wrapper.c' + +echo "Compiling ARM32..." +docker run --rm dockcross/linux-armv7 > dockcross && chmod +x dockcross +./dockcross /bin/bash -c '$CC -shared -fPIC -march=armv7-a -o libc_wrapper_arm32.so linux_libc_wrapper.c' + +echo "Compiling ARM64..." +docker run --rm dockcross/linux-arm64 > dockcross && chmod +x dockcross +./dockcross /bin/bash -c '$CC -shared -fPIC -march=armv8-a -o libc_wrapper_arm64.so linux_libc_wrapper.c' + +chmod 777 libc_wrapper_x86.so +chmod 777 libc_wrapper_x86_64.so +chmod 777 libc_wrapper_arm32.so +chmod 777 libc_wrapper_arm64.so +rm dockcross +echo "Compilation complete. Generated .so files for x86, x86_64, ARM32, and ARM64." \ No newline at end of file diff --git a/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm32.so b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm32.so new file mode 100755 index 000000000..97a2c5b13 Binary files /dev/null and b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm32.so differ diff --git a/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm64.so b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm64.so new file mode 100755 index 000000000..c5c8a83af Binary files /dev/null and b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_arm64.so differ diff --git a/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86.so b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86.so new file mode 100755 index 000000000..462fe4cc7 Binary files /dev/null and b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86.so differ diff --git a/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86_64.so b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86_64.so new file mode 100755 index 000000000..0422b5b9f Binary files /dev/null and b/proprietary/DiskImage/NativeLibraryWrappers/libc_wrapper_x86_64.so differ diff --git a/proprietary/DiskImage/Disk/linux_libc_wrapper.c b/proprietary/DiskImage/NativeLibraryWrappers/linux_libc_wrapper.c similarity index 100% rename from proprietary/DiskImage/Disk/linux_libc_wrapper.c rename to proprietary/DiskImage/NativeLibraryWrappers/linux_libc_wrapper.c