FAT: handle WinNT filename case flags
authorH. Peter Anvin <hpa@zytor.com>
Fri, 5 Feb 2010 02:07:37 +0000 (18:07 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 5 Feb 2010 02:07:37 +0000 (18:07 -0800)
Handle WinNT-style filename case flags (where it uses a shortname only
but with flags to indicate the filename case.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/fat/fat.c
core/fs/fat/fat_fs.h

index 2ec23e0..13cf674 100644 (file)
@@ -680,24 +680,29 @@ static struct dirent * vfat_readdir(struct file *file)
                } else {
                    /* Use the shortname */
                    int i;
+                   uint8_t c;
                    char *p = filename;
                    
                    for (i = 0; i < 8; i++) {
-                       if (de->name[i] == ' ')
+                       c = de->name[i];
+                       if (c == ' ')
                            break;
-                       *p++ = de->name[i];
+                       if (de->lcase & LCASE_BASE)
+                           c = codepage.lower[c];
+                       *p++ = c;
                    }
-                   *p++ = '.';
-                   if (de->name[8] == ' ') {
-                       *--p = '\0';
-                   } else {
+                   if (de->name[8] != ' ') {
+                       *p++ = '.';
                        for (i = 8; i < 11; i++) {
-                           if (de->name[i] == ' ')
+                           c = de->name[i];
+                           if (c == ' ')
                                break;
-                           *p++ = de->name[i];
+                           if (de->lcase & LCASE_EXT)
+                               c = codepage.lower[c];
+                           *p++ = c;
                        }
-                       *p = '\0';
                    }
+                   *p = '\0';
                    
                    goto got;
                }
index db366d6..60b5aee 100644 (file)
@@ -102,7 +102,7 @@ struct fat_sb_info {
 struct fat_dir_entry {
         char     name[11];
         uint8_t  attr;
-        uint8_t  nt_reserved;
+        uint8_t  lcase;
         uint8_t  c_time_tenth;
         uint16_t c_time;
         uint16_t c_date;
@@ -114,7 +114,8 @@ struct fat_dir_entry {
         uint32_t file_size;
 } __attribute__ ((packed));
 
-
+#define LCASE_BASE 8       /* basename is lower case */
+#define LCASE_EXT  16      /* extension is lower case */
 
 struct fat_long_name_entry {
         uint8_t  id;