Changeset 6408be3 in mainline
- 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
- Location:
- uspace
- Files:
-
- 3 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); -
uspace/lib/libblock/libblock.h
r00fe6bb r6408be3 101 101 extern int block_cache_init(dev_handle_t, size_t, unsigned, enum cache_mode); 102 102 103 extern block_t *block_get(dev_handle_t, bn_t, int flags);103 extern block_t *block_get(dev_handle_t, bn_t, int); 104 104 extern void block_put(block_t *); 105 105 106 extern int block_ read(dev_handle_t, off_t *, size_t *, off_t *, void *, size_t,107 size_t );106 extern int block_seqread(dev_handle_t, off_t *, size_t *, off_t *, void *, 107 size_t, size_t); 108 108 109 109 #endif -
uspace/srv/fs/tmpfs/tmpfs_dump.c
r00fe6bb r6408be3 68 68 uint32_t size; 69 69 70 if (block_ read(dev, bufpos, buflen, pos, &entry, sizeof(entry),71 TMPFS_BLOCK_SIZE) != EOK)70 if (block_seqread(dev, bufpos, buflen, pos, &entry, 71 sizeof(entry), TMPFS_BLOCK_SIZE) != EOK) 72 72 return false; 73 73 … … 88 88 } 89 89 90 if (block_ read(dev, bufpos, buflen, pos, fname,90 if (block_seqread(dev, bufpos, buflen, pos, fname, 91 91 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 92 92 ops->destroy(fn); … … 104 104 free(fname); 105 105 106 if (block_ read(dev, bufpos, buflen, pos, &size,106 if (block_seqread(dev, bufpos, buflen, pos, &size, 107 107 sizeof(size), TMPFS_BLOCK_SIZE) != EOK) 108 108 return false; … … 116 116 117 117 nodep->size = size; 118 if (block_ read(dev, bufpos, buflen, pos, nodep->data,118 if (block_seqread(dev, bufpos, buflen, pos, nodep->data, 119 119 size, TMPFS_BLOCK_SIZE) != EOK) 120 120 return false; … … 132 132 } 133 133 134 if (block_ read(dev, bufpos, buflen, pos, fname,134 if (block_seqread(dev, bufpos, buflen, pos, fname, 135 135 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 136 136 ops->destroy(fn); … … 175 175 176 176 char tag[6]; 177 if (block_ read(dev, &bufpos, &buflen, &pos, tag, 5,177 if (block_seqread(dev, &bufpos, &buflen, &pos, tag, 5, 178 178 TMPFS_BLOCK_SIZE) != EOK) 179 179 goto error;
Note:
See TracChangeset
for help on using the changeset viewer.