Ticket #11117: 0001-fat-correctly-read-lowercase-8.3-filenames.patch

File 0001-fat-correctly-read-lowercase-8.3-filenames.patch, 3.7 KB (added by MatejHorvat, 10 years ago)
  • src/add-ons/kernel/file_systems/fat/dir.c

    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,  
    184184    if (start_index == 0xffff) {
    185185        start_index = iter->current_index;
    186186        // 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]);
    188188    }
    189189
    190190    if (oinfo) {
  • src/add-ons/kernel/file_systems/fat/encodings.cpp

    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,  
    15041504/* called to convert a short ms-dos filename to utf8.
    15051505   XXX: encoding is assumed to be standard US code page, never shift-JIS
    15061506*/
    1507 status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower)
     1507status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len,
     1508    uint8 toLower)
    15081509{
    15091510    uchar normalized[8+1+3+1];
    15101511    int32 i, pos;
    status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower)  
    15151516    for (i=0;i<8;i++) {
    15161517        if (msdos[i] == ' ') break;
    15171518        normalized[pos++] = ((i == 0) && (msdos[i] == 5)) ? 0xe5 :
    1518             (toLower ? tolower(msdos[i]) : msdos[i]);
     1519            ((toLower & 0x08) ? tolower(msdos[i]) : msdos[i]);
    15191520    }
    15201521
    15211522    if (msdos[8] != ' ') {
    15221523        normalized[pos++] = '.';
    15231524        for (i=8;i<11;i++) {
    15241525            if (msdos[i] == ' ') break;
    1525             normalized[pos++] = (toLower ? tolower(msdos[i]) : msdos[i]);
     1526            normalized[pos++] = ((toLower & 0x10) ? tolower(msdos[i]) :
     1527                msdos[i]);
    15261528        }
    15271529    }
    15281530
    status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower)  
    15321534            (char *)utf8, (int32 *)&utf8len);
    15331535}
    15341536
    1535 bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], int encoding)
     1537bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11],
     1538    int encoding)
    15361539{
    15371540    int leading = 0;
    15381541    int trailing = 0;
    bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], i  
    15561559            if (*utf8name == '.') return true;
    15571560            trailing++;
    15581561            if (trailing > 3) return true;
    1559             if ((nshort[leading + trailing - 1] == '_') && (*utf8name != '_')) return true;
     1562            if ((nshort[leading + trailing - 1] == '_') && (*utf8name != '_'))
     1563                return true;
    15601564        }
    15611565    }
    15621566
  • src/add-ons/kernel/file_systems/fat/encodings.h

    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);  
    2222status_t generate_short_name(const uchar *name, const uchar *uni,
    2323        uint32 unilen, uchar nshort[11], int *encoding);
    2424
    25 status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len, bool toLower);
     25status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len,
     26    uint8 toLower);
    2627
    2728#ifdef __cplusplus
    2829}