File size filtering update (#320)

* Updated logging

* Updated logging

* Updated logging

* Updated ID/LUN parsing

* Updated handling of max_id

* The -HD option sets type to SAHD

* Replaced is_sasi by device type

* Updated logging

* Logging update

* Improved LUN evaluation

* Check LUN against UnitMax

* Comment update

* LUN parsing update

* Logging update

* Logging update

* Updated ReportLuns

* Updated REPORT LUNS

* Cleanup

* Updated REPORT LUNS

* Updated Execute()

* Updated LUN handling

* Check for consecutive LUNs

* Added LUN check for remotely attached devices

* Remember LUN selected by IDENTIFY

* Evaluate LUN from IDENTIFY message

* Added comment

* Updated REPORT LUNS

* Initlize LUN

* Logging update

* Support 32 LUNs

* rasctl display update

* Updated LUN check for LUNSs > 7

* Simplified LUN validation

* Fixed wrong ID/LUN handling with values > 9

* Log level update

* Manpage update

* rascsi parser update

* Updated error handling

* Updated error handling

* Updated LUN setup validation

* Updated logging

* Improved validation of consecutive LUNs

* Renaming

* Detach all LUNs equal to or higher than the one specified

* File size is not required anymore to be a multiple of the block size

* Renaming
This commit is contained in:
Uwe Seimet 2021-10-13 18:41:21 +02:00 committed by GitHub
parent 89d66ef02b
commit c68c17e366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 53 deletions

View File

@ -1626,11 +1626,6 @@ bool Disk::GetStartAndCount(SASIDEV *controller, uint64_t& start, uint32_t& coun
return true;
}
void Disk::SetSize(uint32_t size)
{
disk.size = size;
}
uint32_t Disk::GetSectorSizeInBytes() const
{
return disk.size ? 1 << disk.size : 0;
@ -1672,11 +1667,16 @@ void Disk::SetSectorSizeInBytes(uint32_t size, bool sasi)
}
}
uint32_t Disk::GetSectorSize() const
uint32_t Disk::GetSectorSizeShiftCount() const
{
return disk.size;
}
void Disk::SetSectorSizeShiftCount(uint32_t size)
{
disk.size = size;
}
bool Disk::IsSectorSizeConfigurable() const
{
return !sector_sizes.empty();

View File

@ -124,10 +124,10 @@ public:
virtual int Read(const DWORD *cdb, BYTE *buf, uint64_t block);
int ReadDefectData10(const DWORD *cdb, BYTE *buf);
void SetSize(uint32_t);
uint32_t GetSectorSizeInBytes() const;
void SetSectorSizeInBytes(uint32_t, bool);
uint32_t GetSectorSize() const;
uint32_t GetSectorSizeShiftCount() const;
void SetSectorSizeShiftCount(uint32_t);
bool IsSectorSizeConfigurable() const;
set<uint32_t> GetSectorSizes() const;
void SetSectorSizes(const set<uint32_t>&);

View File

@ -71,24 +71,11 @@ void SASIHD::Open(const Filepath& path)
// Sector size (default 256 bytes) and number of blocks
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256, true);
SetBlockCount((DWORD)(size >> GetSectorSize()));
SetBlockCount((DWORD)(size >> GetSectorSizeShiftCount()));
#if defined(REMOVE_FIXED_SASIHD_SIZE)
if (size % GetSectorSizeInBytes()) {
stringstream error;
error << "File size must be a multiple of " << GetSectorSizeInBytes() << " bytes but is " << size << " bytes";
throw io_exception(error.str());
}
// 10MB or more
if (size < 0x9f5400) {
throw io_exception("File size must be at least 10 MB");
}
// Limit to about 512MB
if (size > 512 * 1024 * 1024) {
throw io_exception("File size must not exceed 512 MB");
}
// Effective size must be a multiple of the sector size
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
#else
// 10MB, 20MB, 40MBのみ
switch (size) {

View File

@ -431,7 +431,7 @@ void SCSICD::OpenIso(const Filepath& path)
SetBlockCount((DWORD)(size / 0x930));
} else {
// Set the number of blocks
SetBlockCount((DWORD)(size >> GetSectorSize()));
SetBlockCount((DWORD)(size >> GetSectorSizeShiftCount()));
}
// Create only one data track
@ -466,13 +466,11 @@ void SCSICD::OpenPhysical(const Filepath& path)
// Close
fio.Close();
// Size must be a multiple of 512
if (size & 0x1ff) {
throw io_exception("CD-ROM file size must be a multiple of 512 bytes");
}
// Effective size must be a multiple of 512
size = (size / 512) * 512;
// Set the number of blocks
SetBlockCount((DWORD)(size >> GetSectorSize()));
SetBlockCount((DWORD)(size >> GetSectorSizeShiftCount()));
// Create only one data track
ASSERT(!track[0]);
@ -601,7 +599,7 @@ int SCSICD::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
// Recreate the disk cache
Filepath path;
track[index]->GetPath(path);
disk.dcache = new DiskCache(path, GetSectorSize(), GetBlockCount());
disk.dcache = new DiskCache(path, GetSectorSizeShiftCount(), GetBlockCount());
disk.dcache->SetRawMode(rawfile);
// Reset data index

View File

@ -105,14 +105,10 @@ void SCSIHD::Open(const Filepath& path)
// Sector size (default 512 bytes) and number of blocks
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512, false);
SetBlockCount((DWORD)(size >> GetSectorSize()));
SetBlockCount((DWORD)(size >> GetSectorSizeShiftCount()));
// File size must be a multiple of the sector size
if (size % GetSectorSizeInBytes()) {
stringstream error;
error << "File size must be a multiple of " << GetSectorSizeInBytes() << " bytes but is " << size << " bytes";
throw io_exception(error.str());
}
// Effective size must be a multiple of the sector size
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
FinalizeSetup(path, size);
}
@ -182,7 +178,7 @@ bool SCSIHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)
// Mode Parameter header
if (length >= 12) {
// Check the block length bytes
size = 1 << GetSectorSize();
size = 1 << GetSectorSizeShiftCount();
if (buf[9] != (BYTE)(size >> 16) ||
buf[10] != (BYTE)(size >> 8) ||
buf[11] != (BYTE)size) {
@ -203,7 +199,7 @@ bool SCSIHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)
// format device
case 0x03:
// check the number of bytes in the physical sector
size = 1 << GetSectorSize();
size = 1 << GetSectorSizeShiftCount();
if (buf[0xc] != (BYTE)(size >> 8) ||
buf[0xd] != (BYTE)size) {
// currently does not allow changing sector length

View File

@ -69,10 +69,8 @@ void SCSIHD_NEC::Open(const Filepath& path)
}
fio.Close();
// Must be in 512 byte units
if (size & 0x1ff) {
throw io_exception("File size must be a multiple of 512 bytes");
}
// Effective size must be a multiple of 512
size = (size / 512) * 512;
int image_size = 0;
int sector_size = 0;
@ -129,7 +127,7 @@ void SCSIHD_NEC::Open(const Filepath& path)
if (size <= 0 || size > 16) {
throw io_exception("Invalid NEC disk size");
}
SetSize(size);
SetSectorSizeShiftCount(size);
// Number of blocks
SetBlockCount(image_size >> disk.size);

View File

@ -60,7 +60,7 @@ void SCSIMO::Open(const Filepath& path)
if (!SetGeometryForCapacity(size)) {
// Sector size (default 512 bytes) and number of blocks
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512, true);
SetBlockCount(size >> GetSectorSize());
SetBlockCount(size >> GetSectorSizeShiftCount());
}
// File size must be a multiple of the sector size
@ -143,7 +143,7 @@ bool SCSIMO::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)
// Mode Parameter header
if (length >= 12) {
// Check the block length (in bytes)
size = 1 << GetSectorSize();
size = 1 << GetSectorSizeShiftCount();
if (buf[9] != (BYTE)(size >> 16) ||
buf[10] != (BYTE)(size >> 8) || buf[11] != (BYTE)size) {
// Currently does not allow changing sector length
@ -163,7 +163,7 @@ bool SCSIMO::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)
// format device
case 0x03:
// Check the number of bytes in the physical sector
size = 1 << GetSectorSize();
size = 1 << GetSectorSizeShiftCount();
if (buf[0xc] != (BYTE)(size >> 8) ||
buf[0xd] != (BYTE)size) {
// Currently does not allow changing sector length

View File

@ -171,11 +171,6 @@ PbImageFilesInfo *ProtobufResponseHandler::GetAvailableImages(PbResult& result,
LOGTRACE("File '%s' in image folder '%s' has a size of 0 bytes", dir->d_name, image_folder.c_str());
continue;
}
if (st.st_size % 512) {
LOGTRACE("Size of file '%s' in image folder '%s' is not a multiple of 512", dir->d_name, image_folder.c_str());
continue;
}
} else if (dir->d_type == DT_LNK && stat(filename.c_str(), &st)) {
LOGTRACE("Symlink '%s' in image folder '%s' is broken", dir->d_name, image_folder.c_str());
continue;