Skip to content

Commit 8955be1

Browse files
Move Apple copyright page to ScsiBlockcmds class.
1 parent 4931bcb commit 8955be1

4 files changed

Lines changed: 34 additions & 29 deletions

File tree

devices/common/scsi/scsiblockcmds.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ScsiBlockCmds::ScsiBlockCmds() {
3939
}
4040

4141
void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags,
42-
uint8_t density_code)
42+
uint8_t density_code, bool is_apple_compliant)
4343
{
4444
this->medium_type = medium_type;
4545
this->device_flags = dev_flags;
@@ -73,6 +73,9 @@ void ScsiBlockCmds::init_block_device(uint8_t medium_type, uint8_t dev_flags,
7373
}
7474
);
7575
}
76+
77+
if (is_apple_compliant)
78+
this->add_page_getter(this, 0x30, &ScsiBlockCmds::get_apple_copyright_page);
7679
}
7780

7881
void ScsiBlockCmds::process_command() {
@@ -259,3 +262,24 @@ uint32_t ScsiBlockCmds::get_lba() {
259262
ABORT_F("unsupported command length %d in get_lba", cmd_len);
260263
}
261264
}
265+
266+
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
267+
268+
int ScsiBlockCmds::get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
269+
int avail_len)
270+
{
271+
if (subpage && subpage != 0xFFU)
272+
return FORMAT_ERR_BAD_SUBPAGE;
273+
274+
if (ctrl == 3)
275+
return FORMAT_ERR_BAD_CONTROL;
276+
277+
int page_size = 22;
278+
279+
if (page_size > avail_len)
280+
return FORMAT_ERR_DATA_TOO_BIG;
281+
282+
std::memcpy(out_ptr, Apple_Copyright_Page_Data, page_size);
283+
284+
return page_size;
285+
}

devices/common/scsi/scsiblockcmds.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class ScsiBlockCmds : public ScsiCommonCmds {
3838
this->blk_dev = blk_dev_obj;
3939
}
4040

41-
void init_block_device(uint8_t medium_type, uint8_t dev_flags, uint8_t density_code);
41+
void init_block_device(uint8_t medium_type, uint8_t dev_flags,
42+
uint8_t density_code, bool is_apple_compliant);
4243

4344
virtual int read_new();
4445
virtual int write_new();
@@ -55,6 +56,11 @@ class ScsiBlockCmds : public ScsiCommonCmds {
5556
int get_error_recovery_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
5657
int avail_len);
5758

59+
// this page is supported by a bunch of Apple-certified HD and CD-ROM devices
60+
// so implement it here for reusability
61+
int get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
62+
int avail_len);
63+
5864
protected:
5965
virtual void process_command() override;
6066

devices/common/scsi/scsihd.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiPhysDevice(name, m
5353

5454
this->add_page_getter(this, ModePage::DEV_FORMAT_PARAMS, &ScsiHardDisk::get_dev_format_page);
5555
this->add_page_getter(this, ModePage::RIGID_DISK_GEOMETRY, &ScsiHardDisk::get_rigid_geometry_page);
56-
this->add_page_getter(this, 0x30, &ScsiHardDisk::get_apple_copyright_page);
5756
}
5857

5958
void ScsiHardDisk::insert_image(std::string filename) {
@@ -65,7 +64,7 @@ void ScsiHardDisk::insert_image(std::string filename) {
6564

6665
this->is_writeable = true;
6766

68-
this->init_block_device(0, 0, 0);
67+
this->init_block_device(0, 0, 0, true);
6968
}
7069

7170
void ScsiHardDisk::process_command() {
@@ -175,27 +174,6 @@ int ScsiHardDisk::get_rigid_geometry_page(uint8_t ctrl, uint8_t subpage, uint8_t
175174
return page_size;
176175
}
177176

178-
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
179-
180-
int ScsiHardDisk::get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
181-
int avail_len)
182-
{
183-
if (subpage && subpage != 0xFFU)
184-
return FORMAT_ERR_BAD_SUBPAGE;
185-
186-
if (ctrl == 3)
187-
return FORMAT_ERR_BAD_CONTROL;
188-
189-
int page_size = 22;
190-
191-
if (page_size > avail_len)
192-
return FORMAT_ERR_DATA_TOO_BIG;
193-
194-
std::memcpy(out_ptr, Apple_Copyright_Page_Data, page_size);
195-
196-
return page_size;
197-
}
198-
199177
void ScsiHardDisk::format() {
200178
LOG_F(WARNING, "%s: attempt to format the disk!", this->name.c_str());
201179

devices/common/scsi/scsihd.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ScsiHardDisk : public ScsiPhysDevice, public BlockStorageDevice, public Sc
4040
void process_command() override;
4141

4242
protected:
43-
bool is_device_ready() override { return true; }
43+
bool is_device_ready() override { return this->is_ready; }
4444

4545
void mode_select_6(uint8_t param_len);
4646

@@ -50,9 +50,6 @@ class ScsiHardDisk : public ScsiPhysDevice, public BlockStorageDevice, public Sc
5050
int get_rigid_geometry_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
5151
int avail_len);
5252

53-
int get_apple_copyright_page(uint8_t ctrl, uint8_t subpage, uint8_t *out_ptr,
54-
int avail_len);
55-
5653
void format();
5754
void read_buffer();
5855

0 commit comments

Comments
 (0)