mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-08 05:29:40 +00:00
0e8d89e827
* Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
108 lines
2.4 KiB
C++
108 lines
2.4 KiB
C++
//---------------------------------------------------------------------------
|
||
//
|
||
// SCSI Target Emulator RaSCSI (*^..^*)
|
||
// for Raspberry Pi
|
||
//
|
||
// Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp)
|
||
// Copyright (C) 2014-2020 GIMONS
|
||
// Copyright (C) akuker
|
||
//
|
||
// Licensed under the BSD 3-Clause License.
|
||
// See LICENSE file in the project root folder.
|
||
//
|
||
// [ SASI hard disk ]
|
||
//
|
||
//---------------------------------------------------------------------------
|
||
|
||
#include "sasihd.h"
|
||
#include "fileio.h"
|
||
#include "exceptions.h"
|
||
#include "../config.h"
|
||
|
||
SASIHD::SASIHD(const set<uint32_t>& sector_sizes) : Disk("SAHD")
|
||
{
|
||
SetSectorSizes(sector_sizes);
|
||
}
|
||
|
||
void SASIHD::Reset()
|
||
{
|
||
// Unlock, clear attention
|
||
SetLocked(false);
|
||
SetAttn(false);
|
||
|
||
// Reset, clear the code
|
||
SetReset(false);
|
||
SetStatusCode(STATUS_NOERROR);
|
||
}
|
||
|
||
void SASIHD::Open(const Filepath& path)
|
||
{
|
||
assert(!IsReady());
|
||
|
||
// Open as read-only
|
||
Fileio fio;
|
||
if (!fio.Open(path, Fileio::ReadOnly)) {
|
||
throw file_not_found_exception("Can't open SASI hard disk file");
|
||
}
|
||
|
||
// Get file size
|
||
off_t size = fio.GetFileSize();
|
||
fio.Close();
|
||
|
||
// Sector size (default 256 bytes) and number of blocks
|
||
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256, true);
|
||
SetBlockCount((DWORD)(size >> GetSectorSizeShiftCount()));
|
||
|
||
#if defined(REMOVE_FIXED_SASIHD_SIZE)
|
||
// Effective size must be a multiple of the sector size
|
||
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
|
||
#else
|
||
// 10MB, 20MB, 40MBのみ
|
||
switch (size) {
|
||
// 10MB (10441728 BS=256 C=40788)
|
||
case 0x9f5400:
|
||
break;
|
||
|
||
// 20MB (20748288 BS=256 C=81048)
|
||
case 0x13c9800:
|
||
break;
|
||
|
||
// 40MB (41496576 BS=256 C=162096)
|
||
case 0x2793000:
|
||
break;
|
||
|
||
// Other (Not supported )
|
||
default:
|
||
throw io_exception("Unsupported file size");
|
||
}
|
||
#endif // REMOVE_FIXED_SASIHD_SIZE
|
||
|
||
Disk::Open(path);
|
||
FileSupport::SetPath(path);
|
||
}
|
||
|
||
int SASIHD::Inquiry(const DWORD* /*cdb*/, BYTE* /*buf*/)
|
||
{
|
||
SetStatusCode(STATUS_INVALIDCMD);
|
||
return 0;
|
||
}
|
||
|
||
int SASIHD::RequestSense(const DWORD *cdb, BYTE *buf)
|
||
{
|
||
// Size decision
|
||
int size = (int)cdb[4];
|
||
assert(size >= 0 && size < 0x100);
|
||
|
||
// Transfer 4 bytes when size 0 (Shugart Associates System Interface specification)
|
||
if (size == 0) {
|
||
size = 4;
|
||
}
|
||
|
||
// SASI fixed to non-extended format
|
||
memset(buf, 0, size);
|
||
buf[0] = (BYTE)(GetStatusCode() >> 16);
|
||
buf[1] = (BYTE)(GetLun() << 5);
|
||
|
||
return size;
|
||
}
|