Changeset fc840d9 in mainline for uspace/lib/libfs/libfs.c


Ignore:
Timestamp:
2008-10-27T16:53:38Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a5cdded
Parents:
04619ba
Message:

Move libfs_blockread(), block_get() and block_put() to libblock.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libfs/libfs.c

    r04619ba rfc840d9  
    3737#include "libfs.h"
    3838#include "../../srv/vfs/vfs.h"
    39 #include "../../srv/rd/rd.h"
    4039#include <errno.h>
    4140#include <async.h>
     
    332331}
    333332
    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 
    391333/** @}
    392334 */
Note: See TracChangeset for help on using the changeset viewer.