mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-10 02:29:33 +00:00
05db0e4688
* Fixing SonarCloud issues, first round * Fixing SonarCLoud issues, next round * Fixing SonarQube issues, next round * Fixed warning * Replaced empty constructors/destructors with = default; * Fixed warning * Replaced new * Use constants instead of macros * Use structured binding declarations * Use init statements for if * Use string views * Use enum class, use using instead of typedef * Fixed more SonarCloud warnings * Replaced redundant/duplicate types with auto * Devlared methods const * Memory management update * Fixed warning * Added missing const * Improved RaScsiResponse memory management * Improved memory management * Improved memory management * Replaced macros by constants, removed unused constants * Made member private * Fixed warning * Added comment * Fixed shadowing warnings * Cleanup * Cleanup * Cleanup * Fixed shadowing warning * Removed unused code * Fixed more warnings * Removed obsolete casts * Fixed warnings * Removed unused field * Removed library not needed by rasctl * Include cleanup * Updated platform check for better compatibility * Improved check for invalid option. This prevents rasctl to break on macos. * Updated option check * Fixed typo * Added TODO * Removed macro * Scope update * Replaced macro * Added TODO, update memory management * Fixed typo * Replaced NULL by nullptr * Use more structured bindings * Added TODO * Use calloc instead of mallco to not need memset * Fixed warnings * Fixed SonarQube initialization issues * Fixed warning * Cleaned up override/virtual/final * Fixed warnings * Constructor update * Fixed tests * Improved memory management * Added missing const * Added const * Fixed two bugs reported by SonarCloud * Fix SonarCloud hotspot * Fixed memory management * Memory management update * Addressing hotspot by using strncpy * Fixed SonarCloud issues * Fixed SonarQube issues * Added missing const * Added const * Added const * Suppress false positive * Added SonarQube suppressions for false positives * Added suppresoin * Fixed code smells * Reverted changes that is a SonarQube issue, but caused problems with -O3 * Removed TODO based on review
144 lines
3.8 KiB
C++
144 lines
3.8 KiB
C++
//---------------------------------------------------------------------------
|
||
//
|
||
// X68000 EMULATOR "XM6"
|
||
//
|
||
// Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp)
|
||
// Copyright (C) 2014-2020 GIMONS
|
||
//
|
||
// XM6i
|
||
// Copyright (C) 2010-2015 isaki@NetBSD.org
|
||
//
|
||
// Imported sava's Anex86/T98Next image and MO format support patch.
|
||
// Comments translated to english by akuker.
|
||
//
|
||
// [ Disk ]
|
||
//
|
||
//---------------------------------------------------------------------------
|
||
|
||
#pragma once
|
||
|
||
#include "log.h"
|
||
#include "scsi.h"
|
||
#include "device.h"
|
||
#include "device_factory.h"
|
||
#include "disk_track_cache.h"
|
||
#include "file_support.h"
|
||
#include "filepath.h"
|
||
#include "interfaces/scsi_block_commands.h"
|
||
#include "mode_page_device.h"
|
||
#include <string>
|
||
#include <unordered_set>
|
||
#include <unordered_map>
|
||
|
||
using namespace std;
|
||
|
||
class Disk : public ModePageDevice, public ScsiBlockCommands
|
||
{
|
||
private:
|
||
|
||
enum access_mode { RW6, RW10, RW16, SEEK6, SEEK10 };
|
||
|
||
// The supported configurable block sizes, empty if not configurable
|
||
unordered_set<uint32_t> sector_sizes;
|
||
uint32_t configured_sector_size = 0;
|
||
|
||
using disk_t = struct {
|
||
uint32_t size; // Sector Size (9=512, 10=1024, 11=2048, 12=4096)
|
||
uint64_t blocks; // Total number of sectors
|
||
DiskCache *dcache; // Disk cache
|
||
off_t image_offset; // Offset to actual data
|
||
bool is_medium_changed;
|
||
};
|
||
|
||
Dispatcher<Disk> dispatcher;
|
||
|
||
public:
|
||
|
||
explicit Disk(const string&);
|
||
~Disk() override;
|
||
|
||
bool Dispatch() override;
|
||
|
||
void MediumChanged();
|
||
bool Eject(bool) override;
|
||
|
||
// Command helpers
|
||
virtual int WriteCheck(uint64_t);
|
||
virtual void Write(const DWORD *, BYTE *, uint64_t);
|
||
|
||
virtual int Read(const DWORD *, BYTE *, uint64_t);
|
||
|
||
uint32_t GetSectorSizeInBytes() const;
|
||
bool IsSectorSizeConfigurable() const;
|
||
bool SetConfiguredSectorSize(uint32_t);
|
||
uint64_t GetBlockCount() const;
|
||
void FlushCache() override;
|
||
|
||
private:
|
||
|
||
using super = ModePageDevice;
|
||
|
||
// Commands covered by the SCSI specifications (see https://www.t10.org/drafts.htm)
|
||
void StartStopUnit();
|
||
void SendDiagnostic();
|
||
void PreventAllowMediumRemoval();
|
||
void SynchronizeCache10();
|
||
void SynchronizeCache16();
|
||
void ReadDefectData10();
|
||
virtual void Read6();
|
||
void Read10() override;
|
||
void Read16() override;
|
||
virtual void Write6();
|
||
void Write10() override;
|
||
void Write16() override;
|
||
void Verify10();
|
||
void Verify16();
|
||
void Seek();
|
||
void Seek10();
|
||
void ReadCapacity10() override;
|
||
void ReadCapacity16() override;
|
||
void Reserve();
|
||
void Release();
|
||
void Rezero();
|
||
void FormatUnit() override;
|
||
void ReassignBlocks();
|
||
void Seek6();
|
||
void Read(access_mode);
|
||
void Write(access_mode);
|
||
void Verify(access_mode);
|
||
void ReadWriteLong10();
|
||
void ReadWriteLong16();
|
||
void ReadCapacity16_ReadLong16();
|
||
void Format(const DWORD *);
|
||
bool SendDiag(const DWORD *) const;
|
||
bool StartStop(const DWORD *);
|
||
|
||
void ValidateBlockAddress(access_mode) const;
|
||
bool CheckAndGetStartAndCount(uint64_t&, uint32_t&, access_mode);
|
||
|
||
int ModeSense6(const DWORD *, BYTE *, int) override;
|
||
int ModeSense10(const DWORD *, BYTE *, int) override;
|
||
|
||
protected:
|
||
|
||
virtual void Open(const Filepath&);
|
||
|
||
virtual void SetDeviceParameters(BYTE *) const;
|
||
void AddModePages(map<int, vector<BYTE>>&, int, bool) const override;
|
||
virtual void AddErrorPage(map<int, vector<BYTE>>&, bool) const;
|
||
virtual void AddFormatPage(map<int, vector<BYTE>>&, bool) const;
|
||
virtual void AddDrivePage(map<int, vector<BYTE>>&, bool) const;
|
||
void AddCachePage(map<int, vector<BYTE>>&, bool) const;
|
||
virtual void AddVendorPage(map<int, vector<BYTE>>&, int, bool) const;
|
||
unordered_set<uint32_t> GetSectorSizes() const;
|
||
void SetSectorSizes(const unordered_set<uint32_t>&);
|
||
void SetSectorSizeInBytes(uint32_t);
|
||
uint32_t GetSectorSizeShiftCount() const;
|
||
void SetSectorSizeShiftCount(uint32_t);
|
||
uint32_t GetConfiguredSectorSize() const;
|
||
void SetBlockCount(uint64_t);
|
||
|
||
// Internal disk data
|
||
disk_t disk = {};
|
||
};
|