Changeset 25828

Show
Ignore:
Timestamp:
06/06/08 14:53:44 (6 months ago)
Author:
mmlr
Message:

* Unify reading the FAT volume label. One of two places didn't yet handle FAT32

volume labels at all.

* Use the common function in both identifying and mounting the volume so the

name is in sync between what the disk device manager got through scanning and
what Tracker gets through reading the fs stat.

* Strip trailing spaces from volume names in all places.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c

    r25687 r25828  
    147147 
    148148 
     149static void 
     150dosfs_trim_spaces(char *label) 
     151{ 
     152        uint8 index; 
     153        for (index = 10; index > 0; index--) { 
     154                if (label[index] == ' ') 
     155                        label[index] = 0; 
     156                else 
     157                        break; 
     158        } 
     159} 
     160 
     161static bool 
     162dosfs_read_label(bool fat32, uint8 *buffer, char *label) 
     163{ 
     164        uint8 check = fat32 ? 0x42 : 0x29; 
     165        uint8 offset = fat32 ? 0x47 : 0x2b; 
     166 
     167        if (buffer[check] == 0x29 
     168                && memcmp(buffer + offset, "           ", 11) != 0) { 
     169                memcpy(label, buffer + offset, 11); 
     170                dosfs_trim_spaces(label); 
     171                return true; 
     172        } 
     173 
     174        return false; 
     175} 
     176 
     177 
    149178static int 
    150179lock_removable_device(int fd, bool state) 
     
    284313 
    285314        vol->vol_entry = -2;    // for now, assume there is no volume entry 
    286         memset(vol->vol_label, ' ', 11); 
     315        strcpy(vol->vol_label, "no name"); 
    287316 
    288317        // now become more discerning citizens 
     
    312341                        goto error; 
    313342                } 
     343 
     344                if (dosfs_read_label(true, buf, vol->vol_label)) 
     345                        vol->vol_entry = -1; 
    314346        } else { 
    315347                // fat12 & fat16 
     
    352384                } 
    353385 
    354  
    355                 if (buf[0x26] == 0x29) { 
    356                         // fill in the volume label 
    357                         if (memcmp(buf+0x2b, "           ", 11)) { 
    358                                 memcpy(vol->vol_label, buf+0x2b, 11); 
    359                                 vol->vol_entry = -1; 
    360                         } 
    361                 } 
    362  
    363386                vol->fat_mirrored = true; 
    364387                vol->active_fat = 0; 
     
    379402                else 
    380403                        vol->fat_bits = 12; 
     404 
     405                if (dosfs_read_label(false, buf, vol->vol_label)) 
     406                        vol->vol_entry = -1; 
    381407        } 
    382408 
     
    529555                                vol->vol_entry = diri.current_index; 
    530556                                memcpy(vol->vol_label, buffer, 11); 
     557                                dosfs_trim_spaces(vol->vol_label); 
    531558                                break; 
    532559                        } 
     
    536563 
    537564        DPRINTF(0, ("root vnode id = %Lx\n", vol->root_vnode.vnid)); 
    538         DPRINTF(0, ("volume label [%11.11s] (%lx)\n", vol->vol_label, vol->vol_entry)); 
     565        DPRINTF(0, ("volume label [%s] (%lx)\n", vol->vol_label, vol->vol_entry)); 
    539566 
    540567        // steal a trick from bfs 
     
    623650        } 
    624651 
    625         strcpy(name, "no name    "); 
     652        strcpy(name, "no name"); 
    626653        sectors_per_fat = read16(buf,0x16); 
    627654        if (sectors_per_fat == 0) { 
    628655                total_sectors = read32(buf,0x20); 
    629  
    630                 if (buf[0x42] == 0x29) { 
    631                         // fill in FAT32 volume label 
    632                         if (memcmp(buf + 0x47, "           ", 11) != 0) 
    633                                 memcpy(name, buf + 0x47, 11); 
    634                 } 
     656                dosfs_read_label(true, buf, name); 
    635657        } else { 
    636658                total_sectors = read16(buf,0x13); // partition size 
     
    638660                        total_sectors = read32(buf,0x20); 
    639661 
    640                 if (buf[0x26] == 0x29) { 
    641                         // fill in the volume label 
    642                         if (memcmp(buf + 0x2b, "           ", 11) != 0) 
    643                                 memcpy(name, buf + 0x2b, 11); 
    644                 } 
     662                dosfs_read_label(false, buf, name); 
    645663        } 
    646664 
     
    925943                strncpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name)); 
    926944        else 
    927                 strcpy(fss->volume_name, "no name    "); 
     945                strcpy(fss->volume_name, "no name"); 
    928946 
    929947        // XXX: should sanitize name as well 
     
    9971015                                goto bi; 
    9981016                        } 
    999                         if ((buffer[0x26] != 0x29) || memcmp(buffer + 0x2b, vol->vol_label, 11)) { 
     1017                        if ((vol->sectors_per_fat == 0 && (buffer[0x42] != 0x29 
     1018                                || strncmp(buffer + 0x47, vol->vol_label, 11) != 0)) 
     1019                                || (vol->sectors_per_fat != 0 && (buffer[0x26] != 0x29 
     1020                                || strncmp(buffer + 0x2b, vol->vol_label, 11) != 0))) { 
    10001021                                dprintf("dosfs_wfsstat: label mismatch\n"); 
    10011022                                block_cache_set_dirty(vol->fBlockCache, 0, false, tid); 
     
    10031024                        } else { 
    10041025                                memcpy(buffer + 0x2b, name, 11); 
    1005                                 result = 0; 
     1026                                result = B_OK; 
    10061027                        } 
    10071028                        block_cache_put(vol->fBlockCache, 0); 
     
    10131034 
    10141035                        // check if it is the same as the old volume label 
    1015                         if ((buffer == NULL) || (memcmp(buffer, vol->vol_label, 11))) { 
     1036                        if ((buffer == NULL) || (strncmp(buffer, vol->vol_label, 11))) { 
    10161037                                dprintf("dosfs_wfsstat: label mismatch\n"); 
    10171038                                diri_free(&diri); 
     
    10221043                        diri_mark_dirty(&diri); 
    10231044                        diri_free(&diri); 
    1024                         result = 0; 
     1045                        result = B_OK; 
    10251046                } else { 
    10261047                        uint32 index; 
     
    10291050                } 
    10301051 
    1031                 if (result == 0) 
     1052                if (result == B_OK) { 
    10321053                        memcpy(vol->vol_label, name, 11); 
     1054                        dosfs_trim_spaces(vol->vol_label); 
     1055                } 
    10331056        } 
    10341057 
     
    10841107                        dprintf("last allocated cluster = %lx\n", vol->last_allocated); 
    10851108                        dprintf("root vnode id = %Lx\n", vol->root_vnode.vnid); 
    1086                         dprintf("volume label [%11.11s]\n", vol->vol_label); 
     1109                        dprintf("volume label [%s]\n", vol->vol_label); 
    10871110                        break; 
    10881111