From 2e96f8fe6a2951437980751baf101f2fbbcad429 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 11 Jun 2020 12:13:27 +0200 Subject: [PATCH] fat32: Fix handling of non-lfn files --- qloader2.bin | Bin 32768 -> 32768 bytes src/fs/fat32.c | 43 +++++++++++++++++++++++++++++++++++-------- src/lib/libc.c | 14 ++++++++++++++ src/lib/libc.h | 4 ++++ 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/qloader2.bin b/qloader2.bin index 9bd7310e4d36b104179a77bd1063a83b1ba19dce..7e9dfd8ac40f75839e0b0bf4ca7e93f884bea612 100644 GIT binary patch delta 7918 zcma)B4OmoV_P=*vU=VOd<;yP^Kv4ugP*4z2QU|CsFN}OBnYGz;Lo3^5bpKm6*f7O) z8rSvBwtdo)_}jXbo2`jdP@}L6wq@wLyR4d`(e~oFE}Jdu`qBOW&Yi*BkN@*5&olR) z?{nUB&U@~AFLiagx;owd@X)yXxgdC=CA}zkVhK(^e&r3`#>R&}xOyH?dsP1TT-=TI z?+Sw8EFclV9#>jgW0D24An=b91)+(k&JI%}-IXJUuZ7x_*l9%THQJgoiP)ojZT#OO zp@(}zn`RImo6Xs|(8S`&K*~IpE=j5x#W&?^W(F-?Vr{DPQk0sL4Yry?8miskw)7dB zJ0$u39{AP6ucC#f87emxc`~%@=GN0i#dW&z1n!lH2@l-G#=V<8Iag5$@_?}fM2x|eBs+6{yd;lu@Yxr8q5v} zNXx4~juaY9orS8|$#n(l)=0rV(C#c)4xUgO)kq4Rbz)tlu)e)q`O)PKmQCqp6-|C<4r82u|?qMX%7r08ln+Z!=ybjxhG z(btk9I>o)|#!>PH?~F%e%_V~?t5@}3LrOrduqub01?x!ISbsx@4lV4S7qQXoj$Q)V z+7ZKyA9}@ZMQkkO%sOnU_!iqdY@CC5Yw+{w3vpeHUw?53+!d4n6l#b0^fCYn)g4U^ zKiCaW>B>6s_bd4tYm>f-B&^m94fPlOH>&Pf&FT@S<66Sg(eEd~X8I9DBbJqg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b)RO>XXvWRcKLaPm`cluster_num_high << 16 | directory->cluster_num_low; @@ -176,14 +196,21 @@ static int fat32_open_in(struct fat32_context* context, struct fat32_directory_e } } - if ((has_lfn && strcmp(current_lfn, name) == 0) || strncmp(directory_entries[i].file_name_and_ext, name, 8 + 3) == 0) { - *file = directory_entries[i]; - return 0; + if (has_lfn) { + if (!strcmp(current_lfn, name)) { + *file = directory_entries[i]; + return 0; + } + } else { + char fn[8+3]; + fat32_filename_to_8_3(fn, name); + if (!strncmp(directory_entries[i].file_name_and_ext, fn, 8+3)) { + *file = directory_entries[i]; + return 0; + } } - if (has_lfn) { - has_lfn = false; - } + has_lfn = false; } } @@ -192,7 +219,7 @@ static int fat32_open_in(struct fat32_context* context, struct fat32_directory_e if (error != 0) { return error; } - } while (current_cluster_number >= 0x00000002 && current_cluster_number <= 0x0FFFFEF); + } while (current_cluster_number >= 0x00000002 && current_cluster_number <= 0x0FFFFFEF); // file not found return -1; @@ -330,7 +357,7 @@ int fat32_read(struct fat32_file_handle* file, void* buf, uint64_t loc, uint64_t print("fat32: failed to read cluster %x from map\n", current_cluster_number); return r; } - } while (current_cluster_number >= 0x00000002 && current_cluster_number <= 0x0FFFFEF); + } while (current_cluster_number >= 0x00000002 && current_cluster_number <= 0x0FFFFFEF); print("fat32: read failed, unexpected end of cluster chain\n"); return 0; diff --git a/src/lib/libc.c b/src/lib/libc.c index ce45acc5..08ecde55 100644 --- a/src/lib/libc.c +++ b/src/lib/libc.c @@ -2,6 +2,20 @@ #include #include +int toupper(int c) { + if (c >= 'a' && c <= 'z') { + return c - 0x20; + } + return c; +} + +int tolower(int c) { + if (c >= 'A' && c <= 'Z') { + return c + 0x20; + } + return c; +} + void *memcpy(void *dest, const void *src, size_t n) { uint8_t *pdest = dest; const uint8_t *psrc = src; diff --git a/src/lib/libc.h b/src/lib/libc.h index a56bfb85..bffe94a1 100644 --- a/src/lib/libc.h +++ b/src/lib/libc.h @@ -3,10 +3,14 @@ #include +int toupper(int c); +int tolower(int c); + void *memset(void *, int, size_t); void *memcpy(void *, const void *, size_t); int memcmp(const void *, const void *, size_t); void *memmove(void *, const void *, size_t); + char *strcpy(char *, const char *); char *strncpy(char *, const char *, size_t); size_t strlen(const char *);