Changeset 0182e5cc in mainline
- Timestamp:
- 2011-05-24T19:56:11Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1467102
- Parents:
- 88a27f1
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r88a27f1 r0182e5cc 299 299 { 300 300 block_t *b, *b1; 301 uint16_t byte1, byte2; 301 302 aoff64_t offset; 302 303 int rc; 303 304 304 305 offset = (clst + clst/2); 305 306 306 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 307 307 offset / BPS(bs), BLOCK_FLAGS_NONE); 308 308 if (rc != EOK) 309 309 return rc; 310 311 byte1 = ((uint8_t*) b->data)[offset]; 310 312 311 313 /* This cluster access spans a sector boundary. Check only for FAT12 */ … … 324 326 * first byte of next sector 325 327 */ 326 *value = *(uint8_t *)(b->data + BPS(bs) - 1); 327 *value |= *(uint8_t *)(b1->data) << 8; 328 byte2 = ((uint8_t*) b1->data)[0]; 328 329 329 330 rc = block_put(b1); … … 340 341 } 341 342 else 342 *value = *(uint16_t *)(b->data + offset % BPS(bs)); 343 343 byte2 = ((uint8_t*) b->data)[offset+1]; 344 345 #ifdef __BE__ 346 *value = byte2 | (byte1 << 8); 347 #else 348 *value = byte1 | (byte2 << 8); 349 #endif 350 351 *value = uint16_t_le2host(*value); 344 352 if (IS_ODD(clst)) 345 *value = (*value)>> 4;353 *value = *value >> 4; 346 354 else 347 *value = (*value) & FAT12_MASK; 348 349 *value = uint16_t_le2host(*value); 355 *value = *value & FAT12_MASK; 356 350 357 rc = block_put(b); 351 358 … … 408 415 return rc; 409 416 410 *value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs)) & FAT32_MASK);417 *value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs))) & FAT32_MASK; 411 418 412 419 rc = block_put(b); … … 433 440 assert(fatno < FATCNT(bs)); 434 441 435 if (FAT_IS_FAT12(bs)) 442 if (FAT_IS_FAT12(bs)) { 436 443 rc = fat_get_cluster_fat12(bs, devmap_handle, fatno, clst, value); 437 else if (FAT_IS_FAT32(bs)) 438 rc = fat_get_cluster_fat32(bs, devmap_handle, fatno, clst, value); 439 else 440 rc = fat_get_cluster_fat16(bs, devmap_handle, fatno, clst, value); 444 } 445 else { 446 if (FAT_IS_FAT32(bs)) 447 rc = fat_get_cluster_fat32(bs, devmap_handle, fatno, clst, value); 448 else 449 rc = fat_get_cluster_fat16(bs, devmap_handle, fatno, clst, value); 450 } 441 451 442 452 return rc; … … 459 469 block_t *b, *b1=NULL; 460 470 aoff64_t offset; 471 uint16_t byte1, byte2; 461 472 int rc; 462 473 463 474 offset = (clst + clst/2); 464 465 475 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 466 476 offset / BPS(bs), BLOCK_FLAGS_NONE); … … 468 478 return rc; 469 479 470 value = host2uint32_t_le(value); 471 472 uint16_t temp; 480 byte1 = ((uint8_t*) b->data)[offset]; 473 481 bool border = false; 474 482 /* This cluster access spans a sector boundary. Check only for FAT12 */ … … 487 495 * first byte of next sector 488 496 */ 489 temp = *(uint8_t *)(b->data + BPS(bs) - 1); 490 temp |= *(uint8_t *)(b1->data) << 8; 497 byte2 = ((uint8_t*) b1->data)[0]; 491 498 border = true; 492 499 } … … 498 505 } 499 506 else 500 temp = *(uint16_t *)(b->data + offset % BPS(bs));507 byte2 = ((uint8_t*) b->data)[offset+1]; 501 508 502 509 if (IS_ODD(clst)) { 503 temp &= 0x000f; 504 temp |= value << 4; 505 } 506 else { 507 temp &= 0xf000; 508 temp |= value & FAT12_MASK; 509 } 510 510 byte1 &= 0x0f; 511 byte2 = 0; 512 value = (value << 4); 513 } else { 514 byte1 = 0; 515 byte2 &= 0xf0; 516 value &= FAT12_MASK; 517 } 518 519 byte1 = byte1 | (value & 0xff); 520 byte2 = byte2 | (value >> 8); 521 522 ((uint8_t*) b->data)[offset] = byte1; 511 523 if (border) { 512 *(uint8_t *)(b->data + BPS(bs) - 1) = temp & 0xff;513 *(uint8_t *)(b1->data) = temp >> 8; 524 ((uint8_t*) b1->data)[0] = byte2; 525 514 526 b1->dirty = true; 515 } else516 *(uint16_t *)(b->data + offset % BPS(bs)) = temp;517 518 if (b1 && b1->dirty) {519 527 rc = block_put(b1); 520 528 if (rc != EOK) { … … 522 530 return rc; 523 531 } 524 } 532 } else 533 ((uint8_t*) b->data)[offset+1] = byte2; 525 534 526 535 b->dirty = true; /* need to sync block */ … … 554 563 return rc; 555 564 556 *(uint16_t *)(b->data + offset % BPS(bs)) = host2uint 32_t_le(value);565 *(uint16_t *)(b->data + offset % BPS(bs)) = host2uint16_t_le(value); 557 566 558 567 b->dirty = true; /* need to sync block */ -
uspace/srv/fs/fat/fat_fat.h
r88a27f1 r0182e5cc 40 40 #define FAT1 0 41 41 42 #define FAT_CLST_RES0 0 x000043 #define FAT_CLST_RES1 0x000144 #define FAT_CLST_FIRST 0x000242 #define FAT_CLST_RES0 0 43 #define FAT_CLST_RES1 1 44 #define FAT_CLST_FIRST 2 45 45 46 46 #define FAT32_CLST_BAD 0x0ffffff7 -
uspace/srv/fs/fat/fat_ops.c
r88a27f1 r0182e5cc 310 310 311 311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 312 if (FAT_IS_FAT32(bs)) { 313 nodep->firstc = uint16_t_le2host(d->firstc_lo) | 314 (uint16_t_le2host(d->firstc_hi) << 16); 315 } 316 else 317 nodep->firstc = uint16_t_le2host(d->firstc); 318 312 319 if (d->attr & FAT_ATTR_SUBDIR) { 313 320 /* … … 318 325 nodep->type = FAT_DIRECTORY; 319 326 320 327 /* 321 328 * Unfortunately, the 'size' field of the FAT dentry is not 322 329 * defined for the directory entry type. We must determine the 323 330 * size of the directory by walking the FAT. 324 331 */ 332 /* TODO uint16_t clusters to uint32_t */ 325 333 uint16_t clusters; 326 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle, 327 uint16_t_le2host(d->firstc)); 334 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle, nodep->firstc); 328 335 if (rc != EOK) { 329 336 (void) block_put(b); … … 337 344 } 338 345 339 nodep->firstc = uint16_t_le2host(d->firstc);340 346 nodep->lnkcnt = 1; 341 347 nodep->refcnt = 1; … … 1029 1035 return; 1030 1036 } 1037 1031 1038 fs_node_initialize(rfn); 1032 1039 fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
Note:
See TracChangeset
for help on using the changeset viewer.