forked from len0rd/rockbox
get_volume_name generate volume names once then reuse
Change-Id: I36c62bfb28af9770b551a1193fbb66eb6fbac76a
This commit is contained in:
parent
254eaf509e
commit
c0ac043c6d
3 changed files with 31 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue