@@ -373,6 +373,15 @@ static size_t not_ready(struct scsi_ctx *ctx, enum scsi_additional_sense_code as
373
373
return 0 ;
374
374
}
375
375
376
+ static size_t medium_error (struct scsi_ctx * ctx , enum scsi_additional_sense_code asc )
377
+ {
378
+ ctx -> status = CHECK_CONDITION ;
379
+ ctx -> sense_key = MEDIUM_ERROR ;
380
+ ctx -> asc = asc ;
381
+
382
+ return 0 ;
383
+ }
384
+
376
385
void scsi_init (struct scsi_ctx * ctx , const char * disk , const char * vendor ,
377
386
const char * product , const char * revision )
378
387
{
@@ -738,24 +747,32 @@ static size_t store_write_10(struct scsi_ctx *ctx, const uint8_t *buf, size_t le
738
747
{
739
748
uint32_t remaining_sectors ;
740
749
uint32_t sectors ;
750
+ bool error = false;
741
751
742
752
remaining_sectors = ctx -> remaining_data / ctx -> sector_size ;
743
753
sectors = MIN (length , ctx -> remaining_data ) / ctx -> sector_size ;
744
754
if (disk_access_write (ctx -> disk , buf , ctx -> lba , sectors ) != 0 ) {
745
755
/* Flush cache and terminate transfer */
746
756
sectors = 0 ;
747
757
remaining_sectors = 0 ;
758
+ error = true;
748
759
}
749
760
750
761
/* Flush cache if this is the last sector in transfer */
751
762
if (remaining_sectors - sectors == 0 ) {
752
763
if (disk_access_ioctl (ctx -> disk , DISK_IOCTL_CTRL_SYNC , NULL )) {
753
764
LOG_ERR ("Disk cache sync failed" );
765
+ error = true;
754
766
}
755
767
}
756
768
757
769
ctx -> lba += sectors ;
758
- return sectors * ctx -> sector_size ;
770
+
771
+ if (error ) {
772
+ return medium_error (ctx , WRITE_ERROR );
773
+ } else {
774
+ return sectors * ctx -> sector_size ;
775
+ }
759
776
}
760
777
761
778
SCSI_CMD_HANDLER (WRITE_10 )
0 commit comments