summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/pathfuncs.c30
-rw-r--r--firmware/export/pathfuncs.h1
2 files changed, 30 insertions, 1 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index db1935db8b..b5e5ecb0cf 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -127,7 +127,35 @@ void init_volume_names(void)
127 VOL_START_TOK, voldec, volume, VOL_END_TOK); 127 VOL_START_TOK, voldec, volume, VOL_END_TOK);
128 DEBUGF("vol<%d> = %s ", volume, buffer); 128 DEBUGF("vol<%d> = %s ", volume, buffer);
129 } 129 }
130 DEBUGF("\n"); 130 DEBUGF("\n");
131}
132
133#include <stdio.h>
134
135int path_get_volume_id(const char *name)
136{
137 int v = -1;
138
139 if (!name || *name != VOL_START_TOK)
140 goto bail;
141
142 do {
143 switch (*name)
144 {
145 case '0' ... '9': /* digit; parse volume number */
146 v = (v * 10 + *name - '0') % VOL_NUM_MAX;
147 break;
148 case '\0':
149 case PATH_SEPCH: /* no closing bracket; no volume */
150 v = -1;
151 goto bail;
152 default: /* something else; reset volume */
153 v = 0;
154 }
155 } while (*++name != VOL_END_TOK); /* found end token? */
156
157bail:
158 return v;
131} 159}
132 160
133/* Returns on which volume this is and sets *nameptr to the portion of the 161/* Returns on which volume this is and sets *nameptr to the portion of the
diff --git a/firmware/export/pathfuncs.h b/firmware/export/pathfuncs.h
index 73f20f9a52..fce8e5851c 100644
--- a/firmware/export/pathfuncs.h
+++ b/firmware/export/pathfuncs.h
@@ -83,6 +83,7 @@ int 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); 85void init_volume_names(void);
86int path_get_volume_id(const char *name);
86#endif 87#endif
87 88
88int path_strip_drive(const char *name, const char **nameptr, bool greedy); 89int path_strip_drive(const char *name, const char **nameptr, bool greedy);