summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2024-11-04 07:22:49 -0500
committerSolomon Peachy <pizza@shaftnet.org>2024-11-07 07:49:17 -0500
commitf58fad943e40722d1676b3ac0e9d6f9ef665fa02 (patch)
treef7642aecdd7f8b3c983af587508e0eee92ff166e
parente29ddfb6be536da136f862cea35862f463f63b47 (diff)
downloadrockbox-f58fad943e.tar.gz
rockbox-f58fad943e.zip
diskcache: Size the buffers for MAX_LOG_SECTOR_SIZE
Because if we get a logical sector size > min sector size we'll trigger buffer overflows. Change-Id: Ibd24f91a0f8601fbd8c5a5dfeef4ebe5c081f664
-rw-r--r--firmware/common/disk.c4
-rw-r--r--firmware/include/fs_defines.h19
2 files changed, 13 insertions, 10 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 958f09755a..f016a7c196 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -173,7 +173,7 @@ bool disk_init(IF_MD_NONVOID(int drive))
disk_writer_unlock();
#ifdef MAX_LOG_SECTOR_SIZE
- if (info->sector_size > MAX_LOG_SECTOR_SIZE) {
+ if (info->sector_size > MAX_LOG_SECTOR_SIZE || info->sector_size > DC_CACHE_BUFSIZE) {
panicf("Unsupported logical sector size: %d",
info->sector_size);
}
@@ -185,7 +185,7 @@ bool disk_init(IF_MD_NONVOID(int drive))
#endif
#endif /* CONFIG_STORAGE & STORAGE_ATA */
- memset(sector, 0, LOG_SECTOR_SIZE(drive));
+ memset(sector, 0, DC_CACHE_BUFSIZE);
storage_read_sectors(IF_MD(drive,) 0, 1, sector);
bool init = false;
diff --git a/firmware/include/fs_defines.h b/firmware/include/fs_defines.h
index f4c8385d8a..1c8c3afe2b 100644
--- a/firmware/include/fs_defines.h
+++ b/firmware/include/fs_defines.h
@@ -35,14 +35,6 @@
#define MAX_COMPNAME 260
-/* still experimental? */
-/* increasing this will increase the total memory used by the cache; the
- cache, as noted in disk_cache.h, has other minimum requirements that may
- prevent reducing its number of entries in order to compensate */
-#ifndef SECTOR_SIZE
-#define SECTOR_SIZE 512
-#endif
-
/* limits for number of open descriptors - if you increase these values, make
certain that the disk cache has enough available buffers */
@@ -108,7 +100,18 @@
#define DC_MAP_NUM_ENTRIES 256
#endif /* MEMORYSIZE */
+/* increasing this will increase the total memory used by the cache; the
+ cache, as noted in disk_cache.h, has other minimum requirements that may
+ prevent reducing its number of entries in order to compensate */
+#ifndef SECTOR_SIZE
+#define SECTOR_SIZE 512
+#endif
+
/* this _could_ be larger than a sector if that would ever be useful */
+#ifdef MAX_LOG_SECTOR_SIZE
+#define DC_CACHE_BUFSIZE MAX_LOG_SECTOR_SIZE
+#else
#define DC_CACHE_BUFSIZE SECTOR_SIZE
+#endif
#endif /* FS_DEFINES_H */