summaryrefslogtreecommitdiff
path: root/firmware/common/pathfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/pathfuncs.c')
-rw-r--r--firmware/common/pathfuncs.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index 2b4e6a8eb0..5242ec2d32 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -114,7 +114,7 @@ static const unsigned char storage_dec_indexes[STORAGE_NUM_TYPES+1] =
114 */ 114 */
115int path_strip_volume(const char *name, const char **nameptr, bool greedy) 115int path_strip_volume(const char *name, const char **nameptr, bool greedy)
116{ 116{
117 int volume = 0; 117 int volume = ROOT_VOLUME;
118 const char *t = name; 118 const char *t = name;
119 int c, v = 0; 119 int c, v = 0;
120 120
@@ -123,9 +123,15 @@ int path_strip_volume(const char *name, const char **nameptr, bool greedy)
123 * digits within the brackets is parsed as the volume number and of 123 * digits within the brackets is parsed as the volume number and of
124 * those, only the last ones VOL_MUM_MAX allows. 124 * those, only the last ones VOL_MUM_MAX allows.
125 */ 125 */
126 c = *(t = GOBBLE_PATH_SEPCH(t)); /* skip all leading slashes */ 126 t = GOBBLE_PATH_SEPCH(t); /* skip all leading slashes */
127 if (t == name)
128 {
129 volume = -1; /* relative path; don't know */
130 goto psv_out;
131 }
132 c = *t;
127 if (c != VOL_START_TOK) /* missing start token? no volume */ 133 if (c != VOL_START_TOK) /* missing start token? no volume */
128 goto volume0; 134 goto psv_out;
129 135
130 do 136 do
131 { 137 {
@@ -136,7 +142,7 @@ int path_strip_volume(const char *name, const char **nameptr, bool greedy)
136 break; 142 break;
137 case '\0': 143 case '\0':
138 case PATH_SEPCH: /* no closing bracket; no volume */ 144 case PATH_SEPCH: /* no closing bracket; no volume */
139 goto volume0; 145 goto psv_out;
140 default: /* something else; reset volume */ 146 default: /* something else; reset volume */
141 v = 0; 147 v = 0;
142 } 148 }
@@ -146,7 +152,7 @@ int path_strip_volume(const char *name, const char **nameptr, bool greedy)
146 if (!(c = *++t)) /* no more path and no '/' is ok */ 152 if (!(c = *++t)) /* no more path and no '/' is ok */
147 ; 153 ;
148 else if (c != PATH_SEPCH) /* more path and no separator after end */ 154 else if (c != PATH_SEPCH) /* more path and no separator after end */
149 goto volume0; 155 goto psv_out;
150 else if (greedy) 156 else if (greedy)
151 t = GOBBLE_PATH_SEPCH(++t); /* strip remaining separators */ 157 t = GOBBLE_PATH_SEPCH(++t); /* strip remaining separators */
152 158
@@ -155,7 +161,7 @@ int path_strip_volume(const char *name, const char **nameptr, bool greedy)
155 161
156 volume = v; 162 volume = v;
157 name = t; 163 name = t;
158volume0: 164psv_out:
159 if (nameptr) 165 if (nameptr)
160 *nameptr = name; 166 *nameptr = name;
161 return volume; 167 return volume;
@@ -166,10 +172,13 @@ volume0:
166 */ 172 */
167int get_volume_name(int volume, char *buffer) 173int get_volume_name(int volume, char *buffer)
168{ 174{
169 if (volume < 0) 175 if (volume < 0 || volume == ROOT_VOLUME)
170 { 176 {
171 *buffer = '\0'; 177 char *t = buffer;
172 return 0; 178 if (volume == ROOT_VOLUME)
179 *t++ = PATH_ROOTCHR;
180 *t = '\0';
181 return t - buffer;
173 } 182 }
174 183
175 volume %= VOL_NUM_MAX; /* as path parser would have it */ 184 volume %= VOL_NUM_MAX; /* as path parser would have it */
@@ -182,8 +191,20 @@ int get_volume_name(int volume, char *buffer)
182 return snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c", 191 return snprintf(buffer, VOL_MAX_LEN + 1, "%c%s%d%c",
183 VOL_START_TOK, voldec, volume, VOL_END_TOK); 192 VOL_START_TOK, voldec, volume, VOL_END_TOK);
184} 193}
194
195/* Returns volume name formatted with the root. Assumes buffer size is at
196 * least {VOL_MAX_LEN}+2 */
197int make_volume_root(int volume, char *buffer)
198{
199 char *t = buffer;
200 if (volume >= 0 && volume != ROOT_VOLUME)
201 *t++ = PATH_ROOTCHR;
202 t += get_volume_name(volume, t);
203 return t - buffer;
204}
185#endif /* HAVE_MULTIVOLUME */ 205#endif /* HAVE_MULTIVOLUME */
186 206
207
187/* Just like path_strip_volume() but strips a leading drive specifier and 208/* Just like path_strip_volume() but strips a leading drive specifier and
188 * returns the drive number (A=0, B=1, etc.). -1 means no drive was found. 209 * returns the drive number (A=0, B=1, etc.). -1 means no drive was found.
189 * If 'greedy' is 'true', all separators after the volume are consumed. 210 * If 'greedy' is 'true', all separators after the volume are consumed.