Changeset a8c14aa in mainline for uspace/srv/fs/fat/fat_fat.c
- Timestamp:
- 2011-05-02T10:17:33Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 88a27f1
- Parents:
- 979c313a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r979c313a ra8c14aa 380 380 fat_cluster_t clst, fat_cluster_t value) 381 381 { 382 block_t *b, *b1 ;382 block_t *b, *b1=NULL; 383 383 aoff64_t offset; 384 fat_cluster_t *cp, temp; 385 int rc; 386 int spans = 0; 384 int rc; 387 385 388 386 assert(fatno < FATCNT(bs)); … … 398 396 return rc; 399 397 400 /* This cluster access spans a sector boundary. Check only for FAT12 */ 401 if (FAT_IS_FAT12(bs) && (offset % BPS(bs)+1 == BPS(bs))) { 402 /* Is it last sector of FAT? */ 403 if (offset / BPS(bs) < SF(bs)) { 404 /* No. Reading next sector */ 405 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 406 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 407 if (rc != EOK) { 398 value = host2uint32_t_le(value); 399 400 if (FAT_IS_FAT12(bs)) { 401 uint16_t temp; 402 bool border = false; 403 /* This cluster access spans a sector boundary. Check only for FAT12 */ 404 if (offset % BPS(bs)+1 == BPS(bs)) { 405 /* Is it last sector of FAT? */ 406 if (offset / BPS(bs) < SF(bs)) { 407 /* No. Reading next sector */ 408 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 409 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 410 if (rc != EOK) { 411 block_put(b); 412 return rc; 413 } 414 /* 415 * Combining value with last byte of current sector and 416 * first byte of next sector 417 */ 418 temp = *(uint8_t *)(b->data + BPS(bs) - 1); 419 temp |= *(uint8_t *)(b1->data) << 8; 420 border = true; 421 } 422 else { 423 /* Yes. It is last sector of fat */ 408 424 block_put(b); 409 return rc;425 return ERANGE; 410 426 } 411 /* 412 * Combining value with last byte of current sector and 413 * first byte of next sector 414 */ 415 spans=1; 416 cp = &temp; 417 *cp = *(uint8_t *)(b->data + BPS(bs) - 1); 418 *cp |= *(uint8_t *)(b1->data); 427 } 428 else 429 temp = *(uint16_t *)(b->data + offset % BPS(bs)); 430 431 if (IS_ODD(clst)) { 432 temp &= 0x000f; 433 temp |= value << 4; 419 434 } 420 435 else { 421 /* Yes. It is last sector of fat */ 436 temp &= 0xf000; 437 temp |= value & FAT12_MASK; 438 } 439 440 if (border) { 441 *(uint8_t *)(b->data + BPS(bs) - 1) = temp & 0xff; 442 *(uint8_t *)(b1->data) = temp >> 8; 443 b1->dirty = true; 444 } else 445 *(uint16_t *)(b->data + offset % BPS(bs)) = temp; 446 } 447 else { 448 if (FAT_IS_FAT32(bs)) { 449 *(uint32_t *)(b->data + offset % BPS(bs)) &= 0xf0000000; 450 *(uint32_t *)(b->data + offset % BPS(bs)) |= (value & FAT32_MASK); 451 } else 452 *(uint16_t *)(b->data + offset % BPS(bs)) = value; 453 } 454 455 if (b1 && b1->dirty) { 456 rc = block_put(b1); 457 if (rc != EOK) { 422 458 block_put(b); 423 return ERANGE; 424 } 425 } 426 else 427 cp = (fat_cluster_t *)(b->data + offset % BPS(bs)); 428 429 value = host2uint16_t_le(value); 430 if (FAT_IS_FAT12(bs)) { 431 if (clst & 0x0001) { 432 *cp &= 0x000f; 433 *cp |= value << 4; 434 } 435 else { 436 *cp &= 0xf000; 437 *cp |= value & 0x0fff; 438 } 439 440 if (spans) 441 { 442 *(uint8_t *)(b->data + BPS(bs) - 1) = cp[0]; 443 *(uint8_t *)(b1->data) = cp[1]; 444 445 b1->dirty = true; 446 rc = block_put(b1); 447 if (rc != EOK) { 448 block_put(b); 449 return rc; 450 } 451 } 452 } 453 else 454 *cp = value; 459 return rc; 460 } 461 } 455 462 456 463 b->dirty = true; /* need to sync block */
Note:
See TracChangeset
for help on using the changeset viewer.