Explorar o código

fw/diskcache.c: correct the logic for when write needs read

The logic for when a block needs to be read before written (partial
block) was incorrect, would sometimes fail to load a needed block.
H. Peter Anvin %!s(int64=3) %!d(string=hai) anos
pai
achega
29b0ba15a4
Modificáronse 6 ficheiros con 4470 adicións e 4473 borrados
  1. BIN=BIN
      fpga/output_files/max80.jbc
  2. BIN=BIN
      fpga/output_files/max80.jic
  3. BIN=BIN
      fpga/output_files/max80.pof
  4. BIN=BIN
      fpga/output_files/max80.sof
  5. 4462 4462
      fw/boot.mif
  6. 8 11
      fw/diskcache.c

BIN=BIN
fpga/output_files/max80.jbc


BIN=BIN
fpga/output_files/max80.jic


BIN=BIN
fpga/output_files/max80.pof


BIN=BIN
fpga/output_files/max80.sof


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 4462 - 4462
fw/boot.mif


+ 8 - 11
fw/diskcache.c

@@ -235,22 +235,19 @@ DRESULT disk_write(BYTE drive, const BYTE *buffer, LBA_t sectornumber,
     size_t size = sdc.lbasize;
 
     while (block <= last) {
-	struct cache_block *bp = disk_cache_get(block, !!offset);
+	sector_t sector = block << CACHE_BLOCK_BITS;
+	sector_t sectors = min(CACHE_BLOCK_SECTORS, size - sector);
+	size_t block_bytes = sectors << SECTOR_SHIFT;
+	size_t bytes = min(block_bytes - offset, len);
+	struct cache_block *bp;
+
+	bp = disk_cache_get(block, bytes < block_bytes);
 	if (!bp)
 	    return RES_ERROR;
 
-	size_t bytes = min(CACHE_BLOCK_SIZE - offset, len);
-
 	memcpy(bp->data + offset, buffer, bytes);
 
-	sector_t sector = block << CACHE_BLOCK_BITS;
-	int sectors = CACHE_BLOCK_SECTORS;
-
-	if (sector + sectors > size)
-	    sectors = size - sectors; /* Truncated final block */
-
-	if (sdcard_write_sectors(bp->data, block << CACHE_BLOCK_BITS,
-				 sectors) != sectors) {
+	if (sdcard_write_sectors(bp->data, sector, sectors) != sectors) {
 	    invalidate_block(bp);
 	    return RES_ERROR;
 	}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio