summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-07-23 17:30:19 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2024-07-23 18:35:52 -0400
commitc0ac043c6d7b917733df1e0c4f9a74fa54991901 (patch)
tree4b4618bf8d16697d0be050ddf1b34308631ad0af
parent254eaf509e351a1156279a283d9db24df50ce7dd (diff)
downloadrockbox-c0ac043c6d.tar.gz
rockbox-c0ac043c6d.zip
get_volume_name generate volume names once then reuse
Change-Id: I36c62bfb28af9770b551a1193fbb66eb6fbac76a
-rw-r--r--firmware/common/file_internal.c3
-rw-r--r--firmware/common/pathfuncs.c36
-rw-r--r--firmware/export/pathfuncs.h1
3 files changed, 31 insertions, 9 deletions
diff --git a/firmware/common/file_internal.c b/firmware/common/file_internal.c
index e4554670af..28d370e15f 100644
--- a/firmware/common/file_internal.c
+++ b/firmware/common/file_internal.c
@@ -761,4 +761,7 @@ void filesystem_init(void)
mrsw_init(&file_internal_mrsw);
dc_init();
fileobj_mgr_init();
+#ifdef HAVE_MULTIVOLUME
+ init_volume_names();
+#endif
}
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index db3abe6940..d4f4415526 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -24,10 +24,14 @@
#include "pathfuncs.h"
#include "string-extra.h"
#include <stdio.h>
+#include "file_internal.h"
+#include "debug.h"
#ifdef HAVE_MULTIVOLUME
#include "storage.h"
+static char vol_dec_strings[NUM_VOLUMES][ALIGN_UP(VOL_MAX_LEN+2, 4)] = {{0}};
+
enum storage_name_dec_indexes
{
#if (CONFIG_STORAGE & STORAGE_ATA)
@@ -106,6 +110,24 @@ static const unsigned char storage_dec_indexes[STORAGE_NUM_TYPES+1] =
#endif
};
+/* builds a list of drive/volume specifiers <volstr#> */
+void init_volume_names(void)
+{
+ FOR_EACH_VOLUME(-1, volume)
+ {
+ const char *voldec = "";
+ char *buffer = vol_dec_strings[volume];
+
+ int type = storage_driver_type(volume_drive(volume));
+ if (type < 0 || type > STORAGE_NUM_TYPES)
+ type = STORAGE_NUM_TYPES;
+ voldec = storage_dec_names[storage_dec_indexes[type]];
+ snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c",
+ VOL_START_TOK, voldec, volume, VOL_END_TOK);
+ DEBUGF("%s: vol: %d %s", __func__, volume, buffer);
+ }
+}
+
/* Returns on which volume this is and sets *nameptr to the portion of the
* path after the volume specifier, which could be the null if the path is
* just a volume root. If *nameptr > name, then a volume specifier was
@@ -203,7 +225,8 @@ int path_strip_last_volume(const char *name, const char **nameptr, bool greedy)
}
/* Returns the volume specifier decorated with the storage type name.
- * Assumes the supplied buffer size is at least {VOL_MAX_LEN}+1.
+ * Assumes the supplied buffer size is at least {VOL_MAX_LEN}+1,
+ * vol_dec_strings has been initialized by init_volume_names().
*/
int get_volume_name(int volume, char *buffer)
{
@@ -218,17 +241,12 @@ int get_volume_name(int volume, char *buffer)
volume %= VOL_NUM_MAX; /* as path parser would have it */
- int type = storage_driver_type(volume_drive(volume));
- if (type < 0 || type > STORAGE_NUM_TYPES)
- type = STORAGE_NUM_TYPES;
-
- const char *voldec = storage_dec_names[storage_dec_indexes[type]];
- return snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c",
- VOL_START_TOK, voldec, volume, VOL_END_TOK);
+ return strlcpy(buffer, vol_dec_strings[volume], VOL_MAX_LEN + 1);
}
/* Returns volume name formatted with the root. Assumes buffer size is at
- * least {VOL_MAX_LEN}+2 */
+ * least {VOL_MAX_LEN}+2, vol_dec_strings has been initialized by init_volume_names().
+ */
int make_volume_root(int volume, char *buffer)
{
char *t = buffer;
diff --git a/firmware/export/pathfuncs.h b/firmware/export/pathfuncs.h
index 1b18f22d06..73f20f9a52 100644
--- a/firmware/export/pathfuncs.h
+++ b/firmware/export/pathfuncs.h
@@ -82,6 +82,7 @@ int path_strip_volume(const char *name, const char **nameptr, bool greedy);
int path_strip_last_volume(const char *name, const char **nameptr, bool greedy);
int get_volume_name(int volume, char *name);
int make_volume_root(int volume, char *dst);
+void init_volume_names(void);
#endif
int path_strip_drive(const char *name, const char **nameptr, bool greedy);