Changeset fc840d9 in mainline for uspace/lib/libfs/libfs.c
- Timestamp:
- 2008-10-27T16:53:38Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a5cdded
- Parents:
- 04619ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
r04619ba rfc840d9 37 37 #include "libfs.h" 38 38 #include "../../srv/vfs/vfs.h" 39 #include "../../srv/rd/rd.h"40 39 #include <errno.h> 41 40 #include <async.h> … … 332 331 } 333 332 334 /** Read data from a block device.335 *336 * @param phone Phone to be used to communicate with the device.337 * @param buffer Communication buffer shared with the device.338 * @param bufpos Pointer to the first unread valid offset within the339 * communication buffer.340 * @param buflen Pointer to the number of unread bytes that are ready in341 * the communication buffer.342 * @param pos Device position to be read.343 * @param dst Destination buffer.344 * @param size Size of the destination buffer.345 * @param block_size Block size to be used for the transfer.346 *347 * @return True on success, false on failure.348 */349 bool libfs_blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen,350 off_t *pos, void *dst, size_t size, size_t block_size)351 {352 off_t offset = 0;353 size_t left = size;354 355 while (left > 0) {356 size_t rd;357 358 if (*bufpos + left < *buflen)359 rd = left;360 else361 rd = *buflen - *bufpos;362 363 if (rd > 0) {364 /*365 * Copy the contents of the communication buffer to the366 * destination buffer.367 */368 memcpy(dst + offset, buffer + *bufpos, rd);369 offset += rd;370 *bufpos += rd;371 *pos += rd;372 left -= rd;373 }374 375 if (*bufpos == *buflen) {376 /* Refill the communication buffer with a new block. */377 ipcarg_t retval;378 int rc = async_req_2_1(phone, RD_READ_BLOCK,379 *pos / block_size, block_size, &retval);380 if ((rc != EOK) || (retval != EOK))381 return false;382 383 *bufpos = 0;384 *buflen = block_size;385 }386 }387 388 return true;389 }390 391 333 /** @} 392 334 */
Note:
See TracChangeset
for help on using the changeset viewer.