Rev 3251 | Rev 3254 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3251 | Rev 3252 | ||
---|---|---|---|
Line 331... | Line 331... | ||
331 | } |
331 | } |
332 | 332 | ||
333 | #define RD_BASE 1024 // FIXME |
333 | #define RD_BASE 1024 // FIXME |
334 | #define RD_READ_BLOCK (RD_BASE + 1) |
334 | #define RD_READ_BLOCK (RD_BASE + 1) |
335 | 335 | ||
- | 336 | /** Read data from a block device. |
|
- | 337 | * |
|
- | 338 | * @param phone Phone to be used to communicate with the device. |
|
- | 339 | * @param buffer Communication buffer shared with the device. |
|
- | 340 | * @param bufpos Pointer to the first unread valid offset within the |
|
- | 341 | * communication buffer. |
|
- | 342 | * @param buflen Pointer to the number of unread bytes that are ready in |
|
- | 343 | * the communication buffer. |
|
- | 344 | * @param pos Device position to be read. |
|
- | 345 | * @param dst Destination buffer. |
|
- | 346 | * @param size Size of the destination buffer. |
|
- | 347 | * @param block_size Block size to be used for the transfer. |
|
- | 348 | * |
|
- | 349 | * @return True on success, false on failure. |
|
- | 350 | */ |
|
336 | bool libfs_blockread(int phone, void *buffer, size_t *bufpos, size_t *buflen, |
351 | bool libfs_blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen, |
337 | size_t *pos, void *dst, size_t size, size_t block_size) |
352 | off_t *pos, void *dst, size_t size, size_t block_size) |
338 | { |
353 | { |
339 | size_t offset = 0; |
354 | off_t offset = 0; |
340 | size_t left = size; |
355 | size_t left = size; |
341 | 356 | ||
342 | while (left > 0) { |
357 | while (left > 0) { |
343 | size_t rd; |
358 | size_t rd; |
344 | 359 | ||
Line 346... | Line 361... | ||
346 | rd = left; |
361 | rd = left; |
347 | else |
362 | else |
348 | rd = *buflen - *bufpos; |
363 | rd = *buflen - *bufpos; |
349 | 364 | ||
350 | if (rd > 0) { |
365 | if (rd > 0) { |
- | 366 | /* |
|
- | 367 | * Copy the contents of the communication buffer to the |
|
- | 368 | * destination buffer. |
|
- | 369 | */ |
|
351 | memcpy(dst + offset, buffer + *bufpos, rd); |
370 | memcpy(dst + offset, buffer + *bufpos, rd); |
352 | offset += rd; |
371 | offset += rd; |
353 | *bufpos += rd; |
372 | *bufpos += rd; |
354 | *pos += rd; |
373 | *pos += rd; |
355 | left -= rd; |
374 | left -= rd; |
356 | } |
375 | } |
357 | 376 | ||
358 | if (*bufpos == *buflen) { |
377 | if (*bufpos == *buflen) { |
- | 378 | /* Refill the communication buffer with a new block. */ |
|
359 | ipcarg_t retval; |
379 | ipcarg_t retval; |
360 | int rc = async_req_2_1(phone, RD_READ_BLOCK, |
380 | int rc = async_req_2_1(phone, RD_READ_BLOCK, |
361 | *pos / block_size, block_size, &retval); |
381 | *pos / block_size, block_size, &retval); |
362 | if ((rc != EOK) || (retval != EOK)) |
382 | if ((rc != EOK) || (retval != EOK)) |
363 | return false; |
383 | return false; |