Rev 3403 | Rev 3588 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3403 | Rev 3535 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | * Glue code which is commonod to all FS implementations. |
34 | * Glue code which is commonod to all FS implementations. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include "libfs.h" |
37 | #include "libfs.h" |
38 | #include "../../srv/vfs/vfs.h" |
38 | #include "../../srv/vfs/vfs.h" |
39 | #include "../../srv/rd/rd.h" |
- | |
40 | #include <errno.h> |
39 | #include <errno.h> |
41 | #include <async.h> |
40 | #include <async.h> |
42 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
43 | #include <as.h> |
42 | #include <as.h> |
44 | #include <assert.h> |
43 | #include <assert.h> |
Line 329... | Line 328... | ||
329 | ops->node_put(cur); |
328 | ops->node_put(cur); |
330 | if (tmp) |
329 | if (tmp) |
331 | ops->node_put(tmp); |
330 | ops->node_put(tmp); |
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 the |
- | |
339 | * communication buffer. |
- | |
340 | * @param buflen Pointer to the number of unread bytes that are ready in |
- | |
341 | * 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 | else |
- | |
361 | rd = *buflen - *bufpos; |
- | |
362 | - | ||
363 | if (rd > 0) { |
- | |
364 | /* |
- | |
365 | * Copy the contents of the communication buffer to the |
- | |
366 | * 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 | */ |