mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-29 01:49:19 +00:00
41bdcd4aed
* Update logging * Remove duplicate code * Update unit tests * Clean up includes * Merge ProtobufSerializer into protobuf_util namespace * Precompile regex * Add const * Add Split() convenience method, update log level/ID parsing * Move log.h to legacy folder * Elimininate gotos * Fixes for gcc 13 * Update compiler flags * Update default folder handling * Use references instead of pointers * Move code for better encapsulation * Move code * Remove unused method argument * Move device logger * Remove redundant to_string * Rename for consistency * Update handling of protobuf pointers * Simplify protobuf usage * Memory handling update * Add hasher
75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator PiSCSI
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
|
//
|
|
// The base class for all mass storage devices with image file support
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "shared/piscsi_util.h"
|
|
#include "mode_page_device.h"
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <filesystem>
|
|
|
|
using namespace std;
|
|
|
|
class StorageDevice : public ModePageDevice
|
|
{
|
|
public:
|
|
|
|
StorageDevice(PbDeviceType, int);
|
|
~StorageDevice() override = default;
|
|
|
|
void CleanUp() override;
|
|
|
|
virtual void Open() = 0;
|
|
|
|
string GetFilename() const { return filename.string(); }
|
|
void SetFilename(string_view);
|
|
|
|
uint64_t GetBlockCount() const { return blocks; }
|
|
|
|
void ReserveFile() const;
|
|
void UnreserveFile();
|
|
// TODO Remove this method, it is only used by the unit tests
|
|
static void UnreserveAll();
|
|
|
|
static bool FileExists(string_view);
|
|
|
|
void SetMediumChanged(bool b) { medium_changed = b; }
|
|
|
|
static auto GetReservedFiles() { return reserved_files; }
|
|
static void SetReservedFiles(const unordered_map<string, id_set, piscsi_util::StringHash, equal_to<>>& r)
|
|
{ reserved_files = r; }
|
|
static id_set GetIdsForReservedFile(const string&);
|
|
|
|
protected:
|
|
|
|
void ValidateFile();
|
|
|
|
bool IsMediumChanged() const { return medium_changed; }
|
|
|
|
void SetBlockCount(uint64_t b) { blocks = b; }
|
|
|
|
off_t GetFileSize() const;
|
|
|
|
private:
|
|
|
|
bool IsReadOnlyFile() const;
|
|
|
|
uint64_t blocks = 0;
|
|
|
|
filesystem::path filename;
|
|
|
|
bool medium_changed = false;
|
|
|
|
// The list of image files in use and the IDs and LUNs using these files
|
|
static inline unordered_map<string, id_set, piscsi_util::StringHash, equal_to<>> reserved_files;
|
|
};
|