memset(cdb, 0, sizeof(*cdb));
cdb->opcode = opcode;
cdb->lba_be = SCSI_FLIP(lba);
memset(cdb, 0, sizeof(*cdb));
cdb->opcode = opcode;
cdb->lba_be = SCSI_FLIP(lba);
- uint32_t count = size / port->device->block_size;
- if (count == 0) {
- // 对ATAPI设备来说,READ/WRITE (16/12) 没有这个count=0的 special case
- // 但是对于READ/WRITE (6),就存在这个special case
- goto fail;
- }
+ uint32_t count = ICEIL(size, port->device->block_size);
- sata_create_fis(fis, ATA_PACKET, (size << 8) & 0xffffff, 0);
+ sata_create_fis(fis, ATA_PACKET, (size << 8), 0);
+ fis->feature = 1 | ((!write) << 2);
if (port->device->cbd_size == 16) {
scsi_create_packet16((struct scsi_cdb16*)cdb,
write ? SCSI_WRITE_BLOCKS_16 : SCSI_READ_BLOCKS_16,
lba,
count);
if (port->device->cbd_size == 16) {
scsi_create_packet16((struct scsi_cdb16*)cdb,
write ? SCSI_WRITE_BLOCKS_16 : SCSI_READ_BLOCKS_16,
lba,
count);
} else {
scsi_create_packet12((struct scsi_cdb12*)cdb,
write ? SCSI_WRITE_BLOCKS_12 : SCSI_READ_BLOCKS_12,
lba,
count);
} else {
scsi_create_packet12((struct scsi_cdb12*)cdb,
write ? SCSI_WRITE_BLOCKS_12 : SCSI_READ_BLOCKS_12,
lba,
count);