Răsfoiți Sursa

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 3 ani în urmă
părinte
comite
29b0ba15a4
6 a modificat fișierele cu 4470 adăugiri și 4473 ștergeri
  1. BIN
      fpga/output_files/max80.jbc
  2. BIN
      fpga/output_files/max80.jic
  3. BIN
      fpga/output_files/max80.pof
  4. BIN
      fpga/output_files/max80.sof
  5. 4462 4462
      fw/boot.mif
  6. 8 11
      fw/diskcache.c

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


Fișier diff suprimat deoarece este prea mare
+ 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;
 	}

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff