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