Changeset 6408be3 in mainline for uspace/lib/libblock/libblock.c
- Timestamp:
- 2009-06-28T12:08:07Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4198f9c3
- Parents:
- 00fe6bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r00fe6bb r6408be3 81 81 } devcon_t; 82 82 83 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,84 const void *src);83 static int read_block(devcon_t *devcon, bn_t boff, size_t block_size); 84 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size); 85 85 86 86 static devcon_t *devcon_search(dev_handle_t dev_handle) … … 212 212 return ENOMEM; 213 213 214 off_t bufpos = 0; 215 size_t buflen = 0; 216 rc = block_read(dev_handle, &bufpos, &buflen, &off, 217 bb_buf, size, size); 214 rc = read_block(devcon, 0, size); 218 215 if (rc != EOK) { 219 216 free(bb_buf); 220 217 return rc; 221 218 } 219 220 memcpy(bb_buf, devcon->com_area, size); 221 222 222 devcon->bb_buf = bb_buf; 223 223 devcon->bb_off = off; … … 340 340 */ 341 341 int rc; 342 off_t bufpos = 0;343 size_t buflen = 0;344 off_t pos = boff * cache->block_size;345 342 bool sync = false; 346 343 … … 400 397 * the new contents from the device. 401 398 */ 402 rc = block_read(dev_handle, &bufpos, &buflen, &pos, 403 b->data, cache->block_size, cache->block_size); 399 rc = read_block(devcon, b->boff, cache->block_size); 404 400 assert(rc == EOK); 401 memcpy(b->data, devcon->com_area, cache->block_size); 405 402 } 406 403 … … 435 432 list_append(&block->free_link, &cache->free_head); 436 433 if (cache->mode != CACHE_MODE_WB && block->dirty) { 437 rc = write_block(devcon, block->boff, block->size,438 block->data);434 memcpy(devcon->com_area, block->data, block->size); 435 rc = write_block(devcon, block->boff, block->size); 439 436 assert(rc == EOK); 440 437 … … 446 443 } 447 444 448 /** Read data from a block device.445 /** Read sequential data from a block device. 449 446 * 450 447 * @param dev_handle Device handle of the block device. … … 460 457 * @return EOK on success or a negative return code on failure. 461 458 */ 462 int 463 block_read(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen, off_t *pos, 464 void *dst, size_t size, size_t block_size) 459 int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen, 460 off_t *pos, void *dst, size_t size, size_t block_size) 465 461 { 466 462 off_t offset = 0; … … 491 487 if (*bufpos == (off_t) *buflen) { 492 488 /* Refill the communication buffer with a new block. */ 493 i pcarg_t retval;494 int rc = async_req_2_1(devcon->dev_phone, BD_READ_BLOCK, 495 *pos / block_size, block_size, &retval);496 if ( (rc != EOK) || (retval != EOK))497 return (rc != EOK ? rc : (int) retval);489 int rc; 490 491 rc = read_block(devcon, *pos / block_size, block_size); 492 if (rc != EOK) 493 return rc; 498 494 499 495 *bufpos = 0; … … 502 498 } 503 499 500 return EOK; 501 } 502 503 /** Read block from block device. 504 * 505 * @param devcon Device connection. 506 * @param boff Block index. 507 * @param block_size Block size. 508 * @param src Buffer for storing the data. 509 * 510 * @return EOK on success or negative error code on failure. 511 */ 512 static int read_block(devcon_t *devcon, bn_t boff, size_t block_size) 513 { 514 ipcarg_t retval; 515 int rc; 516 517 assert(devcon); 518 rc = async_req_2_1(devcon->dev_phone, BD_READ_BLOCK, boff, block_size, 519 &retval); 520 if ((rc != EOK) || (retval != EOK)) 521 return (rc != EOK ? rc : (int) retval); 522 504 523 return EOK; 505 524 } … … 514 533 * @return EOK on success or negative error code on failure. 515 534 */ 516 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size, 517 const void *src) 535 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size) 518 536 { 519 537 ipcarg_t retval; … … 521 539 522 540 assert(devcon); 523 memcpy(devcon->com_area, src, block_size); 524 525 rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK, 526 boff, block_size, &retval); 541 rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK, boff, block_size, 542 &retval); 527 543 if ((rc != EOK) || (retval != EOK)) 528 544 return (rc != EOK ? rc : (int) retval);
Note:
See TracChangeset
for help on using the changeset viewer.