mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 20:29:46 +00:00
CD-ROM: Add max blocks check.
The code does not support more than 2^32 - 2 blocks because of this expression: static_cast<uint32_t>(this->size_blocks + 1)
This commit is contained in:
parent
655b9a17e1
commit
3978d0754d
@ -25,9 +25,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size) {
|
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size, const uint64_t max_blocks) {
|
||||||
this->block_size = block_size;
|
this->block_size = block_size;
|
||||||
this->cache_size = cache_blocks * this->block_size;
|
this->cache_size = cache_blocks * this->block_size;
|
||||||
|
this->max_blocks = max_blocks;
|
||||||
|
|
||||||
// allocate device cache and fill it with zeroes
|
// allocate device cache and fill it with zeroes
|
||||||
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
|
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
|
||||||
@ -46,6 +47,9 @@ int BlockStorageDevice::set_host_file(std::string file_path) {
|
|||||||
|
|
||||||
this->size_bytes = this->img_file.size();
|
this->size_bytes = this->img_file.size();
|
||||||
this->size_blocks = this->size_bytes / this->block_size;
|
this->size_blocks = this->size_bytes / this->block_size;
|
||||||
|
if (this->size_blocks > this->max_blocks)
|
||||||
|
return -1;
|
||||||
|
|
||||||
this->set_fpos(0);
|
this->set_fpos(0);
|
||||||
|
|
||||||
this->is_ready = true;
|
this->is_ready = true;
|
||||||
|
@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
class BlockStorageDevice {
|
class BlockStorageDevice {
|
||||||
public:
|
public:
|
||||||
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512);
|
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512, const uint64_t max_blocks=0xffffffffffffffff);
|
||||||
~BlockStorageDevice();
|
~BlockStorageDevice();
|
||||||
|
|
||||||
void set_block_size(const int blk_size) { this->block_size = blk_size; };
|
void set_block_size(const int blk_size) { this->block_size = blk_size; };
|
||||||
@ -49,6 +49,7 @@ protected:
|
|||||||
ImgFile img_file;
|
ImgFile img_file;
|
||||||
uint64_t size_bytes = 0; // image file size in bytes
|
uint64_t size_bytes = 0; // image file size in bytes
|
||||||
uint64_t size_blocks = 0; // image file size in blocks
|
uint64_t size_blocks = 0; // image file size in blocks
|
||||||
|
uint64_t max_blocks = 0; // maximum number of blocks supported
|
||||||
uint64_t cur_fpos = 0; // current image file pointer position
|
uint64_t cur_fpos = 0; // current image file pointer position
|
||||||
uint32_t block_size = 512; // physical block size
|
uint32_t block_size = 512; // physical block size
|
||||||
uint32_t cache_size = 0; // cache size
|
uint32_t cache_size = 0; // cache size
|
||||||
|
@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
CdromDrive::CdromDrive() : BlockStorageDevice(31, 2048) {
|
CdromDrive::CdromDrive() : BlockStorageDevice(31, 2048, 0xfffffffe) {
|
||||||
this->is_writeable = false;
|
this->is_writeable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ uint32_t CdromDrive::request_sense(uint8_t *data_ptr, uint8_t sense_key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
|
uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
|
||||||
WRITE_DWORD_BE_A(data_ptr, this->size_blocks);
|
WRITE_DWORD_BE_A(data_ptr, static_cast<uint32_t>(this->size_blocks));
|
||||||
WRITE_DWORD_BE_A(&data_ptr[4], this->block_size);
|
WRITE_DWORD_BE_A(&data_ptr[4], this->block_size);
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user