@@ -80,7 +80,9 @@ static void cmd_write_sectors(atacontroller_t *pCont) {
8080 ASSERT ( ((pDev -> reg [REG_DEVICE_HEAD ] >> 6 )& 1 ) == 1 , "CHS Translation not implemented" );
8181
8282 pCont -> pCurrDev -> writeBufferOffset = 0 ;
83- pCont -> pCurrDev -> writeBuffer = (uint8 * )calloc (1 ,512 );
83+ pCont -> pCurrDev -> writeBufferSize = pDev -> reg [REG_SECTOR_COUNT ] * 512 ;
84+ ASSERT (pDev -> reg [REG_SECTOR_COUNT ]!= 0 ,"Does 0 mean 256 here?" );
85+ pCont -> pCurrDev -> writeBuffer = (uint8 * )calloc (pDev -> reg [REG_SECTOR_COUNT ],512 );
8486 pCont -> pCurrDev -> writeBufferLBA = lba ;
8587
8688 // Signal that the data is ready
@@ -472,17 +474,17 @@ static void pio_outw(io_handler_t *handler,uint16 address,uint16 val) {
472474 pCont -> pCurrDev -> writeBufferOffset += 2 ;
473475 //LOG("Data written at 0x%04x, offset is now %i",address,pCont->pCurrDev->writeBufferOffset);
474476
475- if ( pCont -> pCurrDev -> writeBufferOffset == 512 ) {
477+ if ( pCont -> pCurrDev -> writeBufferOffset == pCont -> pCurrDev -> writeBufferSize ) {
476478 int r ;
477479
478- LOG ("Writing 512bytes to LBA %u" ,pCont -> pCurrDev -> writeBufferLBA );
480+ LOG ("Writing %u bytes to LBA %u" , pCont -> pCurrDev -> writeBufferSize ,pCont -> pCurrDev -> writeBufferLBA );
479481 r = lseek64 (pCont -> pCurrDev -> backingfile ,
480482 (uint64 )pCont -> pCurrDev -> writeBufferLBA * 512LL ,SEEK_SET );
481483 if (r == -1 ) perror ("Seek-for-write" );
482484
483485 r = write (pCont -> pCurrDev -> backingfile ,
484486 pCont -> pCurrDev -> writeBuffer ,
485- 512 );
487+ pCont -> pCurrDev -> writeBufferSize );
486488 if (r == -1 ) perror ("Write-for-write" );
487489
488490 pCont -> pCurrDev -> reg [REG_STATUS ] = BIT_STATUS_DRDY ;
0 commit comments