diff options
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r-- | firmware/drivers/fat.c | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index e9f2b2442d..999e6f1c9b 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -1172,44 +1172,19 @@ static int write_long_name(struct fat_file* file, | |||
1172 | 1172 | ||
1173 | return 0; | 1173 | return 0; |
1174 | } | 1174 | } |
1175 | static bool is_char_legal(char c) | 1175 | |
1176 | { | ||
1177 | switch(c) | ||
1178 | { | ||
1179 | case 0x22: /* " */ | ||
1180 | case 0x2a: /* * */ | ||
1181 | case 0x2b: /* + */ | ||
1182 | case 0x2c: /* , */ | ||
1183 | case 0x2e: /* . */ | ||
1184 | case 0x3a: /* : */ | ||
1185 | case 0x3b: /* ; */ | ||
1186 | case 0x3c: /* < */ | ||
1187 | case 0x3d: /* = */ | ||
1188 | case 0x3e: /* > */ | ||
1189 | case 0x3f: /* ? */ | ||
1190 | case 0x5b: /* [ */ | ||
1191 | case 0x5c: /* \ */ | ||
1192 | case 0x5d: /* ] */ | ||
1193 | case 0x7c: /* | */ | ||
1194 | return false; | ||
1195 | default: | ||
1196 | if(c < 0x20) /* Control Characters */ | ||
1197 | return false; | ||
1198 | } | ||
1199 | return true; | ||
1200 | } | ||
1201 | static int fat_checkname(const unsigned char* newname) | 1176 | static int fat_checkname(const unsigned char* newname) |
1202 | { | 1177 | { |
1178 | static const char invalid_chars[] = "\"*/:<>?\\|"; | ||
1203 | int len = strlen(newname); | 1179 | int len = strlen(newname); |
1204 | /* More sanity checks are probably needed */ | 1180 | /* More sanity checks are probably needed */ |
1205 | if (len > 255 || newname[len - 1] == '.' || | 1181 | if (len > 255 || newname[len - 1] == '.') |
1206 | newname[0] == ' ' || newname[len - 1] == ' ' ) | ||
1207 | { | 1182 | { |
1208 | return -1; | 1183 | return -1; |
1209 | } | 1184 | } |
1210 | while (*newname) | 1185 | while (*newname) |
1211 | { | 1186 | { |
1212 | if (!is_char_legal(*newname)) | 1187 | if (*newname < ' ' || strchr(invalid_chars, *newname) != NULL) |
1213 | return -1; | 1188 | return -1; |
1214 | newname++; | 1189 | newname++; |
1215 | } | 1190 | } |
@@ -1380,19 +1355,19 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1380 | 1355 | ||
1381 | static unsigned char char2dos(unsigned char c, int* randomize) | 1356 | static unsigned char char2dos(unsigned char c, int* randomize) |
1382 | { | 1357 | { |
1383 | if (!is_char_legal(c)) | 1358 | static const char invalid_chars[] = "\"*+,./:;<=>?[\\]|"; |
1359 | |||
1360 | if (c <= 0x20) | ||
1361 | c = 0; /* Illegal char, remove */ | ||
1362 | else if (strchr(invalid_chars, c) != NULL) | ||
1384 | { | 1363 | { |
1385 | if(c <= 0x20) | 1364 | /* Illegal char, replace */ |
1386 | c = 0; /* Illegal char, remove */ | 1365 | c = '_'; |
1387 | else | 1366 | *randomize = 1; /* as per FAT spec */ |
1388 | { | ||
1389 | /* Illegal char, replace */ | ||
1390 | c = '_'; | ||
1391 | *randomize = 1; /* as per FAT spec */ | ||
1392 | } | ||
1393 | } | 1367 | } |
1394 | else | 1368 | else |
1395 | c = toupper(c); | 1369 | c = toupper(c); |
1370 | |||
1396 | return c; | 1371 | return c; |
1397 | } | 1372 | } |
1398 | 1373 | ||