@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2323#include < loguru.hpp>
2424#include < memaccess.h>
2525
26- ScsiBlockCmds::ScsiBlockCmds (int cache_blocks) : BlockStorageDevice(cache_blocks ) {
26+ ScsiBlockCmds::ScsiBlockCmds () {
2727 this ->enable_cmd (ScsiCommand::READ_6);
2828 this ->enable_cmd (ScsiCommand::READ_10);
2929 this ->enable_cmd (ScsiCommand::READ_12);
@@ -44,21 +44,21 @@ void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags) {
4444
4545 phy_impl->set_read_more_data_cb (
4646 [this ](int * dsize, uint8_t ** dptr) -> bool {
47- if (this ->remain_size ) {
48- *dsize = this ->read_more ();
49- *dptr = ( uint8_t *) this ->data_cache . get ();
47+ if (this ->blk_dev -> get_remaining_size () ) {
48+ *dsize = this ->blk_dev -> read_more ();
49+ *dptr = this ->blk_dev -> get_cache_ptr ();
5050 return true ;
5151 } else
5252 return false ;
5353 }
5454 );
5555
56- if (this ->is_writeable ) {
56+ if (this ->blk_dev -> medium_writable () ) {
5757 phy_impl->set_write_more_data_cb (
5858 [this ](int * dsize, uint8_t ** dptr) -> bool {
59- if (this ->remain_size ) {
60- *dsize = this ->write_more ();
61- *dptr = ( uint8_t *) this ->data_cache . get ();
59+ if (this ->blk_dev -> get_remaining_size () ) {
60+ *dsize = this ->blk_dev -> write_more ();
61+ *dptr = this ->blk_dev -> get_cache_ptr ();
6262 return true ;
6363 } else
6464 return false ;
@@ -131,9 +131,9 @@ int ScsiBlockCmds::read_new() {
131131 return ScsiPhase::STATUS;
132132 }
133133
134- this ->set_fpos (this ->get_lba ());
135- phy_impl->set_xfer_len (this ->read_begin (nblocks));
136- phy_impl->set_buffer (( uint8_t *) this ->data_cache . get ());
134+ this ->blk_dev -> set_fpos (this ->get_lba ());
135+ phy_impl->set_xfer_len (this ->blk_dev -> read_begin (nblocks));
136+ phy_impl->set_buffer (this ->blk_dev -> get_cache_ptr ());
137137
138138 return ScsiPhase::DATA_IN;
139139}
@@ -161,12 +161,12 @@ int ScsiBlockCmds::write_new() {
161161 return ScsiPhase::STATUS;
162162 }
163163
164- this ->set_fpos (this ->get_lba ());
165- phy_impl->set_xfer_len (this ->write_begin (nblocks));
166- phy_impl->set_buffer (( uint8_t *) this ->data_cache . get ());
164+ this ->blk_dev -> set_fpos (this ->get_lba ());
165+ phy_impl->set_xfer_len (this ->blk_dev -> write_begin (nblocks));
166+ phy_impl->set_buffer (this ->blk_dev -> get_cache_ptr ());
167167
168168 phy_impl->set_post_xfer_action ([this ]() {
169- this ->write_cache ();
169+ this ->blk_dev -> write_cache ();
170170 }
171171 );
172172
@@ -203,8 +203,8 @@ int ScsiBlockCmds::read_capacity() {
203203 return ScsiPhase::STATUS;
204204 }
205205
206- uint32_t last_lba = this ->size_blocks - 1 ;
207- uint32_t blk_len = this ->block_size ;
206+ uint32_t last_lba = this ->blk_dev -> get_size_in_blocks () - 1 ;
207+ uint32_t blk_len = this ->blk_dev -> get_block_size () ;
208208
209209 WRITE_DWORD_BE_A (&this ->buf_ptr [0 ], last_lba);
210210 WRITE_DWORD_BE_A (&this ->buf_ptr [4 ], blk_len);
@@ -217,10 +217,12 @@ int ScsiBlockCmds::read_capacity() {
217217int ScsiBlockCmds::format_block_descriptors (uint8_t * out_ptr) {
218218 uint8_t density_code = 0 ;
219219
220- uint32_t nblocks = std::min ((int64_t )this ->size_blocks , (int64_t )0xFFFFFFFFUL );
220+ uint32_t nblocks = std::min ((int64_t )this ->blk_dev ->get_size_in_blocks (),
221+ (int64_t )0xFFFFFFFFUL );
221222
222223 WRITE_DWORD_BE_A (&out_ptr[0 ], nblocks);
223- WRITE_DWORD_BE_A (&out_ptr[4 ], (density_code << 24 ) | (this ->block_size & 0xFFFFFF ));
224+ WRITE_DWORD_BE_A (&out_ptr[4 ], (density_code << 24 ) |
225+ (this ->blk_dev ->get_block_size () & 0xFFFFFF ));
224226
225227 return 8 ;
226228}
0 commit comments