Skip to content

Commit

Permalink
fix win32 compile
Browse files Browse the repository at this point in the history
  • Loading branch information
XUranus committed Mar 31, 2024
1 parent f5b4ba6 commit 0a69bb7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ set(
${CMAKE_PREFIX_PATH}
)

# in order to be compatible with older cmake (<3.25) that CMAKE_HOST_LINUX not introduced
message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(CMAKE_HOST_LINUX true)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(CMAKE_HOST_WIN32 true)
endif()

find_package(
OpenSSL 3
Expand Down Expand Up @@ -76,8 +83,8 @@ file(
"include/native/*.h"
)

message("VOLUMEPROTECTPROTECT_SOURCES = ${VOLUMEPROTECTPROTECT_SOURCES}")
message("VOLUMEPROTECTPROTECT_HEADERS = ${VOLUMEPROTECTPROTECT_HEADERS}")
# message("VOLUMEPROTECTPROTECT_SOURCES = ${VOLUMEPROTECTPROTECT_SOURCES}")
# message("VOLUMEPROTECTPROTECT_HEADERS = ${VOLUMEPROTECTPROTECT_HEADERS}")

include_directories(
"include"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Volume backup/restore library and cli tools for Windows and Linux
- MSVC2015+/GCC4.9+
- Windows/Linux
- OpenSSL 3.0+
- `libblkid-dev`,`uuid-dev` for Linux
- `libblkid-dev`,`uuid-dev`,`liblvm2-dev` for Linux

## Build
clone this repository and it's dependency recusively:
Expand Down
26 changes: 26 additions & 0 deletions include/native/linux/LvmUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file LvmUtils.h
* @brief Provide linux LVM api wrapper for liblvm2app to manipulate snapshots.
* @copyright Copyright 2023-2024 XUranus. All rights reserved.
* @license This project is released under the Apache License.
* @author XUranus([email protected])
*/

#ifndef VOLUMEBACKUP_LINUX_LVM_UTILS_HEADER
#define VOLUMEBACKUP_LINUX_LVM_UTILS_HEADER

#include <string>

#ifdef __linux__

namespace volumeprotect {
namespace linuxlvmutil {

bool CreateSnapshot(const std::string& vg, const std::string& pv, const std::string& snapshotName);

}
}

#endif

#endif
4 changes: 4 additions & 0 deletions include/native/win32/Win32RawIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Win32RawDataReader : public RawDataReader {
~Win32RawDataReader();
bool Read(uint64_t offset, uint8_t* buffer, int length, ErrCodeType& errorCode) override;
bool Ok() override;
HandleType Handle() override;
ErrCodeType Error() override;

private:
Expand All @@ -62,6 +63,7 @@ class Win32RawDataWriter : public RawDataWriter {
~Win32RawDataWriter();
bool Write(uint64_t offset, uint8_t* buffer, int length, ErrCodeType& errorCode) override;
bool Ok() override;
HandleType Handle() override;
bool Flush() override;
ErrCodeType Error() override;

Expand All @@ -81,6 +83,7 @@ class Win32VirtualDiskVolumeRawDataReader : public RawDataReader {
~Win32VirtualDiskVolumeRawDataReader();
bool Read(uint64_t offset, uint8_t* buffer, int length, ErrCodeType& errorCode) override;
bool Ok() override;
HandleType Handle() override;
ErrCodeType Error() override;

private:
Expand All @@ -99,6 +102,7 @@ class Win32VirtualDiskVolumeRawDataWriter : public RawDataWriter {
~Win32VirtualDiskVolumeRawDataWriter();
bool Write(uint64_t offset, uint8_t* buffer, int length, ErrCodeType& errorCode) override;
bool Ok() override;
HandleType Handle() override;
bool Flush() override;
ErrCodeType Error() override;

Expand Down
20 changes: 20 additions & 0 deletions src/native/win32/Win32RawIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ bool Win32RawDataReader::Ok()
return m_handle != INVALID_HANDLE_VALUE;
}

HandleType Win32RawDataReader::Handle()
{
return m_handle;
}

ErrCodeType Win32RawDataReader::Error()
{
return static_cast<ErrCodeType>(::GetLastError());
Expand Down Expand Up @@ -262,6 +267,11 @@ bool Win32RawDataWriter::Ok()
return m_handle != INVALID_HANDLE_VALUE;
}

HandleType Win32RawDataWriter::Handle()
{
return m_handle;
}

bool Win32RawDataWriter::Flush()
{
if (!Ok()) {
Expand Down Expand Up @@ -402,6 +412,11 @@ bool Win32VirtualDiskVolumeRawDataReader::Ok()
return (m_volumeReader == nullptr) ? false : m_volumeReader->Ok();
}

HandleType Win32VirtualDiskVolumeRawDataReader::Handle()
{
return Ok() ? m_volumeReader->Handle() : NULL;
}

ErrCodeType Win32VirtualDiskVolumeRawDataReader::Error()
{
return (m_volumeReader == nullptr) ? ::GetLastError() : m_volumeReader->Error();
Expand Down Expand Up @@ -444,6 +459,11 @@ bool Win32VirtualDiskVolumeRawDataWriter::Ok()
return (m_volumeWriter == nullptr) ? false : m_volumeWriter->Ok();
}

HandleType Win32VirtualDiskVolumeRawDataWriter::Handle()
{
return Ok() ? m_volumeWriter->Handle() : NULL;
}

bool Win32VirtualDiskVolumeRawDataWriter::Flush()
{
return (m_volumeWriter == nullptr) ? false : m_volumeWriter->Flush();
Expand Down

0 comments on commit 0a69bb7

Please sign in to comment.