Changeset 25828
- Timestamp:
- 06/06/08 14:53:44 (6 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c
r25687 r25828 147 147 148 148 149 static void 150 dosfs_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 161 static bool 162 dosfs_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 149 178 static int 150 179 lock_removable_device(int fd, bool state) … … 284 313 285 314 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"); 287 316 288 317 // now become more discerning citizens … … 312 341 goto error; 313 342 } 343 344 if (dosfs_read_label(true, buf, vol->vol_label)) 345 vol->vol_entry = -1; 314 346 } else { 315 347 // fat12 & fat16 … … 352 384 } 353 385 354 355 if (buf[0x26] == 0x29) {356 // fill in the volume label357 if (memcmp(buf+0x2b, " ", 11)) {358 memcpy(vol->vol_label, buf+0x2b, 11);359 vol->vol_entry = -1;360 }361 }362 363 386 vol->fat_mirrored = true; 364 387 vol->active_fat = 0; … … 379 402 else 380 403 vol->fat_bits = 12; 404 405 if (dosfs_read_label(false, buf, vol->vol_label)) 406 vol->vol_entry = -1; 381 407 } 382 408 … … 529 555 vol->vol_entry = diri.current_index; 530 556 memcpy(vol->vol_label, buffer, 11); 557 dosfs_trim_spaces(vol->vol_label); 531 558 break; 532 559 } … … 536 563 537 564 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)); 539 566 540 567 // steal a trick from bfs … … 623 650 } 624 651 625 strcpy(name, "no name ");652 strcpy(name, "no name"); 626 653 sectors_per_fat = read16(buf,0x16); 627 654 if (sectors_per_fat == 0) { 628 655 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); 635 657 } else { 636 658 total_sectors = read16(buf,0x13); // partition size … … 638 660 total_sectors = read32(buf,0x20); 639 661 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); 645 663 } 646 664 … … 925 943 strncpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name)); 926 944 else 927 strcpy(fss->volume_name, "no name ");945 strcpy(fss->volume_name, "no name"); 928 946 929 947 // XXX: should sanitize name as well … … 997 1015 goto bi; 998 1016 } 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))) { 1000 1021 dprintf("dosfs_wfsstat: label mismatch\n"); 1001 1022 block_cache_set_dirty(vol->fBlockCache, 0, false, tid); … … 1003 1024 } else { 1004 1025 memcpy(buffer + 0x2b, name, 11); 1005 result = 0;1026 result = B_OK; 1006 1027 } 1007 1028 block_cache_put(vol->fBlockCache, 0); … … 1013 1034 1014 1035 // 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))) { 1016 1037 dprintf("dosfs_wfsstat: label mismatch\n"); 1017 1038 diri_free(&diri); … … 1022 1043 diri_mark_dirty(&diri); 1023 1044 diri_free(&diri); 1024 result = 0;1045 result = B_OK; 1025 1046 } else { 1026 1047 uint32 index; … … 1029 1050 } 1030 1051 1031 if (result == 0)1052 if (result == B_OK) { 1032 1053 memcpy(vol->vol_label, name, 11); 1054 dosfs_trim_spaces(vol->vol_label); 1055 } 1033 1056 } 1034 1057 … … 1084 1107 dprintf("last allocated cluster = %lx\n", vol->last_allocated); 1085 1108 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); 1087 1110 break; 1088 1111
