mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Device: Add disk write driver framework
At the moment, no drivers are implemented, so all devices have Access::None.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#ifndef __DISKDRIVER_H__
|
||||
#define __DISKDRIVER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
namespace Disk {
|
||||
|
||||
constexpr const std::chrono::milliseconds DefaultTimeout{2000};
|
||||
constexpr const size_t SectorSize = 512;
|
||||
enum class Access {
|
||||
None,
|
||||
EntireCard,
|
||||
VSA
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface for drivers which work with block data on devices
|
||||
*/
|
||||
class Driver {
|
||||
public:
|
||||
virtual ~Driver() = default;
|
||||
virtual Access getAccess() const = 0;
|
||||
virtual std::pair<uint32_t, uint32_t> getBlockSizeBounds() const = 0;
|
||||
};
|
||||
|
||||
} // namespace Disk
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __DISKDRIVER_H__
|
||||
@@ -6,29 +6,21 @@
|
||||
#include "icsneo/platform/optional.h"
|
||||
#include "icsneo/communication/communication.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/disk/diskdriver.h"
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
namespace Disk {
|
||||
|
||||
/**
|
||||
* Interface for drivers which read block data from devices
|
||||
*/
|
||||
class DiskReadDriver {
|
||||
class ReadDriver : public virtual Driver {
|
||||
public:
|
||||
static constexpr const std::chrono::milliseconds DefaultTimeout{2000};
|
||||
static constexpr const size_t SectorSize = 512;
|
||||
enum class Access {
|
||||
None,
|
||||
EntireCard,
|
||||
VSA
|
||||
};
|
||||
|
||||
virtual ~DiskReadDriver() = default;
|
||||
virtual optional<uint64_t> readLogicalDisk(Communication& com, device_eventhandler_t report,
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout);
|
||||
virtual Access getAccess() const = 0;
|
||||
virtual std::pair<uint32_t, uint32_t> getBlockSizeBounds() const = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -41,7 +33,9 @@ protected:
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Disk
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __DISKREADDRIVER_H__
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef __DISKWRITEDRIVER_H__
|
||||
#define __DISKWRITEDRIVER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/platform/optional.h"
|
||||
#include "icsneo/communication/communication.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/disk/diskreaddriver.h"
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
namespace Disk {
|
||||
|
||||
/**
|
||||
* Interface for drivers which write block data from devices
|
||||
*/
|
||||
class WriteDriver : public virtual Driver {
|
||||
public:
|
||||
virtual optional<uint64_t> writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver,
|
||||
uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Flag returned from writeLogicalDiskAligned when the
|
||||
* operation failed to be performed atomically and can
|
||||
* be retried after rereading.
|
||||
*/
|
||||
static const uint64_t RetryAtomic;
|
||||
|
||||
/**
|
||||
* The severity to report with when an atomic operation
|
||||
* is requested that the driver is unable to attempt.
|
||||
*/
|
||||
static const APIEvent::Severity NonatomicSeverity;
|
||||
|
||||
/**
|
||||
* Perform a write which the driver can do in one shot.
|
||||
*
|
||||
* The `pos` requested must be sector-aligned, and the `amount` must be
|
||||
* within the block size bounds provided by the driver.
|
||||
*
|
||||
* If `atomicBuf` is provided, it will be used to ensure that the disk
|
||||
* data changes from `atomicBuf` to `from` without trampling any reads
|
||||
* that may have happened while modifying the data.
|
||||
*
|
||||
* The flag `RetryAtomic` is returned if the operation was attempted
|
||||
* atomically but failed.
|
||||
*
|
||||
* If the driver does not support atomic operations, but `atomicBuf`
|
||||
* is non-null, an APIEvent::AtomicOperationCompletedNonatomically
|
||||
* should be reported with `NonatomicSeverity`.
|
||||
*/
|
||||
virtual optional<uint64_t> writeLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) = 0;
|
||||
};
|
||||
|
||||
} // namespace Disk
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __DISKWRITEDRIVER_H__
|
||||
@@ -8,12 +8,14 @@
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
namespace Disk {
|
||||
|
||||
/**
|
||||
* A disk read driver which uses the neoMemory command to read from the disk
|
||||
*
|
||||
* This can only request reads by sector, so it will be very slow, but is likely supported by any device with a disk
|
||||
*/
|
||||
class NeoMemoryDiskReadDriver : public DiskReadDriver {
|
||||
class NeoMemoryDiskReadDriver : public ReadDriver {
|
||||
public:
|
||||
Access getAccess() const override { return Access::VSA; }
|
||||
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override {
|
||||
@@ -29,7 +31,9 @@ private:
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Disk
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __NEOMEMORYDISKREADDRIVER_H__
|
||||
@@ -4,19 +4,24 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/disk/diskreaddriver.h"
|
||||
#include "icsneo/disk/diskwritedriver.h"
|
||||
#include <limits>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
namespace Disk {
|
||||
|
||||
/**
|
||||
* A disk driver which always returns the requested disk as unsupported
|
||||
*
|
||||
* Used for devices which do not have a disk, or do not provide any means for accessing it
|
||||
*/
|
||||
class NullDiskReadDriver : public DiskReadDriver {
|
||||
class NullDriver : public ReadDriver, public WriteDriver {
|
||||
public:
|
||||
optional<uint64_t> readLogicalDisk(Communication& com, device_eventhandler_t report,
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override;
|
||||
optional<uint64_t> writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver,
|
||||
uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override;
|
||||
Access getAccess() const override { return Access::None; }
|
||||
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override {
|
||||
static_assert(SectorSize <= std::numeric_limits<uint32_t>::max(), "Incorrect sector size");
|
||||
@@ -27,9 +32,13 @@ public:
|
||||
private:
|
||||
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override;
|
||||
optional<uint64_t> writeLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Disk
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __NULLDISKREADDRIVER_H__
|
||||
Reference in New Issue
Block a user