summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
761 mrsw_init(&file_internal_mrsw); 761 mrsw_init(&file_internal_mrsw);
762 dc_init(); 762 dc_init();
763 fileobj_mgr_init(); 763 fileobj_mgr_init();
764#ifdef HAVE_MULTIVOLUME
765 init_volume_names();
766#endif
764} 767}
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 @@
24#include "pathfuncs.h" 24#include "pathfuncs.h"
25#include "string-extra.h" 25#include "string-extra.h"
26#include <stdio.h> 26#include <stdio.h>
27#include "file_internal.h"
28#include "debug.h"
27 29
28#ifdef HAVE_MULTIVOLUME 30#ifdef HAVE_MULTIVOLUME
29#include "storage.h" 31#include "storage.h"
30 32
33static char vol_dec_strings[NUM_VOLUMES][ALIGN_UP(VOL_MAX_LEN+2, 4)] = {{0}};
34
31enum storage_name_dec_indexes 35enum storage_name_dec_indexes
32{ 36{
33#if (CONFIG_STORAGE & STORAGE_ATA) 37#if (CONFIG_STORAGE & STORAGE_ATA)
@@ -106,6 +110,24 @@ static const unsigned char storage_dec_indexes[STORAGE_NUM_TYPES+1] =
106#endif 110#endif
107}; 111};
108 112
113/* builds a list of drive/volume specifiers <volstr#> */
114void init_volume_names(void)
115{
116 FOR_EACH_VOLUME(-1, volume)
117 {
118 const char *voldec = "";
119 char *buffer = vol_dec_strings[volume];
120
121 int type = storage_driver_type(volume_drive(volume));
122 if (type < 0 || type > STORAGE_NUM_TYPES)
123 type = STORAGE_NUM_TYPES;
124 voldec = storage_dec_names[storage_dec_indexes[type]];
125 snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c",
126 VOL_START_TOK, voldec, volume, VOL_END_TOK);
127 DEBUGF("%s: vol: %d %s", __func__, volume, buffer);
128 }
129}
130
109/* Returns on which volume this is and sets *nameptr to the portion of the 131/* Returns on which volume this is and sets *nameptr to the portion of the
110 * path after the volume specifier, which could be the null if the path is 132 * path after the volume specifier, which could be the null if the path is
111 * just a volume root. If *nameptr > name, then a volume specifier was 133 * 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)
203} 225}
204 226
205/* Returns the volume specifier decorated with the storage type name. 227/* Returns the volume specifier decorated with the storage type name.
206 * Assumes the supplied buffer size is at least {VOL_MAX_LEN}+1. 228 * Assumes the supplied buffer size is at least {VOL_MAX_LEN}+1,
229 * vol_dec_strings has been initialized by init_volume_names().
207 */ 230 */
208int get_volume_name(int volume, char *buffer) 231int get_volume_name(int volume, char *buffer)
209{ 232{
@@ -218,17 +241,12 @@ int get_volume_name(int volume, char *buffer)
218 241
219 volume %= VOL_NUM_MAX; /* as path parser would have it */ 242 volume %= VOL_NUM_MAX; /* as path parser would have it */
220 243
221 int type = storage_driver_type(volume_drive(volume)); 244 return strlcpy(buffer, vol_dec_strings[volume], VOL_MAX_LEN + 1);
222 if (type < 0 || type > STORAGE_NUM_TYPES)
223 type = STORAGE_NUM_TYPES;
224
225 const char *voldec = storage_dec_names[storage_dec_indexes[type]];
226 return snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c",
227 VOL_START_TOK, voldec, volume, VOL_END_TOK);
228} 245}
229 246
230/* Returns volume name formatted with the root. Assumes buffer size is at 247/* Returns volume name formatted with the root. Assumes buffer size is at
231 * least {VOL_MAX_LEN}+2 */ 248 * least {VOL_MAX_LEN}+2, vol_dec_strings has been initialized by init_volume_names().
249 */
232int make_volume_root(int volume, char *buffer) 250int make_volume_root(int volume, char *buffer)
233{ 251{
234 char *t = buffer; 252 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);
82int path_strip_last_volume(const char *name, const char **nameptr, bool greedy); 82int path_strip_last_volume(const char *name, const char **nameptr, bool greedy);
83int get_volume_name(int volume, char *name); 83int get_volume_name(int volume, char *name);
84int make_volume_root(int volume, char *dst); 84int make_volume_root(int volume, char *dst);
85void init_volume_names(void);
85#endif 86#endif
86 87
87int path_strip_drive(const char *name, const char **nameptr, bool greedy); 88int path_strip_drive(const char *name, const char **nameptr, bool greedy);