From a7c0a3106c15e31f2c52b958574fea83ae5979b7 Mon Sep 17 00:00:00 2001
From: Matej Horvat <matej.horvat@guest.arnes.si>
Date: Sat, 8 Nov 2014 12:41:50 +0100
Subject: [PATCH] fat: correctly read lowercase 8.3 filenames
---
src/add-ons/kernel/file_systems/fat/dir.c | 2 +-
src/add-ons/kernel/file_systems/fat/encodings.cpp | 14 +++++++++-----
src/add-ons/kernel/file_systems/fat/encodings.h | 3 ++-
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/add-ons/kernel/file_systems/fat/dir.c b/src/add-ons/kernel/file_systems/fat/dir.c
index 62eddab..cbf8464 100644
a
|
b
|
_next_dirent_(struct diri *iter, struct _dirent_info_ *oinfo, char *filename,
|
184 | 184 | if (start_index == 0xffff) { |
185 | 185 | start_index = iter->current_index; |
186 | 186 | // korli : seen on FreeBSD /src/sys/fs/msdosfs/direntry.h |
187 | | msdos_to_utf8(buffer, (uchar *)filename, len, buffer[0xc] & 0x18); |
| 187 | msdos_to_utf8(buffer, (uchar *)filename, len, buffer[0xc]); |
188 | 188 | } |
189 | 189 | |
190 | 190 | if (oinfo) { |
diff --git a/src/add-ons/kernel/file_systems/fat/encodings.cpp b/src/add-ons/kernel/file_systems/fat/encodings.cpp
index 1561b38..e3d2f7e 100644
a
|
b
|
status_t generate_short_name(const uchar *name, const uchar *uni,
|
1504 | 1504 | /* called to convert a short ms-dos filename to utf8. |
1505 | 1505 | XXX: encoding is assumed to be standard US code page, never shift-JIS |
1506 | 1506 | */ |
1507 | | status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower) |
| 1507 | status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, |
| 1508 | uint8 toLower) |
1508 | 1509 | { |
1509 | 1510 | uchar normalized[8+1+3+1]; |
1510 | 1511 | int32 i, pos; |
… |
… |
status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower)
|
1515 | 1516 | for (i=0;i<8;i++) { |
1516 | 1517 | if (msdos[i] == ' ') break; |
1517 | 1518 | normalized[pos++] = ((i == 0) && (msdos[i] == 5)) ? 0xe5 : |
1518 | | (toLower ? tolower(msdos[i]) : msdos[i]); |
| 1519 | ((toLower & 0x08) ? tolower(msdos[i]) : msdos[i]); |
1519 | 1520 | } |
1520 | 1521 | |
1521 | 1522 | if (msdos[8] != ' ') { |
1522 | 1523 | normalized[pos++] = '.'; |
1523 | 1524 | for (i=8;i<11;i++) { |
1524 | 1525 | if (msdos[i] == ' ') break; |
1525 | | normalized[pos++] = (toLower ? tolower(msdos[i]) : msdos[i]); |
| 1526 | normalized[pos++] = ((toLower & 0x10) ? tolower(msdos[i]) : |
| 1527 | msdos[i]); |
1526 | 1528 | } |
1527 | 1529 | } |
1528 | 1530 | |
… |
… |
status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower)
|
1532 | 1534 | (char *)utf8, (int32 *)&utf8len); |
1533 | 1535 | } |
1534 | 1536 | |
1535 | | bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], int encoding) |
| 1537 | bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], |
| 1538 | int encoding) |
1536 | 1539 | { |
1537 | 1540 | int leading = 0; |
1538 | 1541 | int trailing = 0; |
… |
… |
bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], i
|
1556 | 1559 | if (*utf8name == '.') return true; |
1557 | 1560 | trailing++; |
1558 | 1561 | if (trailing > 3) return true; |
1559 | | if ((nshort[leading + trailing - 1] == '_') && (*utf8name != '_')) return true; |
| 1562 | if ((nshort[leading + trailing - 1] == '_') && (*utf8name != '_')) |
| 1563 | return true; |
1560 | 1564 | } |
1561 | 1565 | } |
1562 | 1566 | |
diff --git a/src/add-ons/kernel/file_systems/fat/encodings.h b/src/add-ons/kernel/file_systems/fat/encodings.h
index 782c492..633e43f 100644
a
|
b
|
status_t munge_short_name1(uchar nshort[11], int iteration, int encoding);
|
22 | 22 | status_t generate_short_name(const uchar *name, const uchar *uni, |
23 | 23 | uint32 unilen, uchar nshort[11], int *encoding); |
24 | 24 | |
25 | | status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower); |
| 25 | status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, |
| 26 | uint8 toLower); |
26 | 27 | |
27 | 28 | #ifdef __cplusplus |
28 | 29 | } |