Ticket #4602: dosfs_volume_name2.diff

File dosfs_volume_name2.diff, 1.9 KB (added by romain, 13 years ago)

sanatize volume name

  • util.c

     
    164164        c = (c << 7) + (c >> 1) + *(p++);
    165165    return c;
    166166}
     167
     168
     169void sanatize_name(char *name, int length)
     170{
     171    int i;
     172
     173    // XXX: should sanitize name as well
     174    for (i = length - 1; i > 0; i--)
     175        if (name[i] != ' ')
     176            break;
     177    name[i + 1] = 0;
     178    for (; i >= 0; i--) {
     179        if ((name[i] >= 'A') && (name[i] <= 'Z'))
     180            name[i] += 'a' - 'A';
     181    }
     182
     183}
  • dosfs.c

     
    765765
    766766    cookie->bytes_per_sector = bytes_per_sector;
    767767    cookie->total_sectors = total_sectors;
     768    sanatize_name(name, 12);
    768769    strlcpy(cookie->name, name, 12);
    769770    *_cookie = cookie;
    770771
     
    994995dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
    995996{
    996997    nspace* vol = (nspace*)_vol->private_volume;
    997     int i;
    998998
    999999    LOCK_VOL(vol);
    10001000
     
    10211021    strncpy(fss->device_name, vol->device, sizeof(fss->device_name));
    10221022
    10231023    if (vol->vol_entry > -2)
    1024         strncpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name));
     1024        strlcpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name));
    10251025    else
    10261026        strcpy(fss->volume_name, "no name");
    10271027
    1028     // XXX: should sanitize name as well
    1029     for (i=10;i>0;i--)
    1030         if (fss->volume_name[i] != ' ')
    1031             break;
    1032     fss->volume_name[i+1] = 0;
    1033     for (;i>=0;i--) {
    1034         if ((fss->volume_name[i] >= 'A') && (fss->volume_name[i] <= 'Z'))
    1035             fss->volume_name[i] += 'a' - 'A';
    1036     }
     1028    sanatize_name(fss->volume_name, 11);
    10371029
    10381030    // File system name
    10391031    strcpy(fss->fsh_name, "fat");
  • util.h

     
    2525uint32  time_t2dos(time_t s);
    2626
    2727uint8   hash_msdos_name(const char *name);
     28void sanatize_name(char *name, int length);
    2829
    2930#if 0
    3031#define read32(buffer,off) \