瀏覽代碼

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 年之前
父節點
當前提交
29b0ba15a4
共有 6 個文件被更改,包括 4470 次插入4473 次删除
  1. 二進制
      fpga/output_files/max80.jbc
  2. 二進制
      fpga/output_files/max80.jic
  3. 二進制
      fpga/output_files/max80.pof
  4. 二進制
      fpga/output_files/max80.sof
  5. 4462 4462
      fw/boot.mif
  6. 8 11
      fw/diskcache.c

二進制
fpga/output_files/max80.jbc


二進制
fpga/output_files/max80.jic


二進制
fpga/output_files/max80.pof


二進制
fpga/output_files/max80.sof


文件差異過大導致無法顯示
+ 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;
 	}

部分文件因文件數量過多而無法顯示