Changeset fc840d9 in mainline


Ignore:
Timestamp:
2008-10-27T16:53:38Z (16 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.

Location:
uspace
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r04619ba rfc840d9  
    3535        lib/libc \
    3636        lib/libfs \
     37        lib/libblock \
    3738        lib/softint \
    3839        lib/softfloat \
  • 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 */
  • uspace/lib/libfs/libfs.h

    r04619ba rfc840d9  
    7070extern void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
    7171
    72 extern bool libfs_blockread(int, void *, off_t *, size_t *, off_t *, void *,
    73     size_t, size_t);
    74 
    7572#endif
    7673
  • uspace/srv/fs/fat/Makefile

    r04619ba rfc840d9  
    3232LIBC_PREFIX = ../../../lib/libc
    3333LIBFS_PREFIX = ../../../lib/libfs
     34LIBBLOCK_PREFIX = ../../../lib/libblock
    3435SOFTINT_PREFIX = ../../../lib/softint
    3536include $(LIBC_PREFIX)/Makefile.toolchain
    3637
    37 CFLAGS += -I $(LIBFS_PREFIX)
     38CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
    3839
    39 LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
     40LIBS = \
     41        $(LIBC_PREFIX)/libc.a \
     42        $(LIBFS_PREFIX)/libfs.a \
     43        $(LIBBLOCK_PREFIX)/libblock.a
    4044
    4145## Sources
  • uspace/srv/fs/fat/fat.h

    r04619ba rfc840d9  
    198198} fat_node_t;
    199199
    200 /* TODO move somewhere else */
    201 typedef struct block {
    202         void *data;
    203         size_t size;
    204         bool dirty;
    205 } block_t;
    206 
    207 extern block_t *block_get(dev_handle_t, off_t, size_t);
    208 extern void block_put(block_t *);
    209 
    210200extern fs_reg_t fat_reg;
    211201
  • uspace/srv/fs/fat/fat_fat.c

    r04619ba rfc840d9  
    4141#include "../../vfs/vfs.h"
    4242#include <libfs.h>
     43#include <libblock.h>
    4344#include <errno.h>
    4445#include <byteorder.h>
  • uspace/srv/fs/fat/fat_ops.c

    r04619ba rfc840d9  
    4141#include "../../vfs/vfs.h"
    4242#include <libfs.h>
     43#include <libblock.h>
    4344#include <ipc/ipc.h>
    4445#include <ipc/services.h>
     
    6061/** List of cached free FAT nodes. */
    6162static LIST_INITIALIZE(ffn_head);
    62 
    63 static int dev_phone = -1;              /* FIXME */
    64 static void *dev_buffer = NULL;         /* FIXME */
    65 
    66 block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
    67 {
    68         /* FIXME */
    69         block_t *b;
    70         off_t bufpos = 0;
    71         size_t buflen = 0;
    72         off_t pos = offset * bs;
    73 
    74         assert(dev_phone != -1);
    75         assert(dev_buffer);
    76 
    77         b = malloc(sizeof(block_t));
    78         if (!b)
    79                 return NULL;
    80        
    81         b->data = malloc(bs);
    82         if (!b->data) {
    83                 free(b);
    84                 return NULL;
    85         }
    86         b->size = bs;
    87 
    88         if (!libfs_blockread(dev_phone, dev_buffer, &bufpos, &buflen, &pos,
    89             b->data, bs, bs)) {
    90                 free(b->data);
    91                 free(b);
    92                 return NULL;
    93         }
    94 
    95         return b;
    96 }
    97 
    98 void block_put(block_t *block)
    99 {
    100         /* FIXME */
    101         free(block->data);
    102         free(block);
    103 }
    10463
    10564static void fat_node_initialize(fat_node_t *node)
  • uspace/srv/fs/tmpfs/Makefile

    r04619ba rfc840d9  
    3232LIBC_PREFIX = ../../../lib/libc
    3333LIBFS_PREFIX = ../../../lib/libfs
     34LIBBLOCK_PREFIX = ../../../lib/libblock
    3435SOFTINT_PREFIX = ../../../lib/softint
    3536include $(LIBC_PREFIX)/Makefile.toolchain
    3637
    37 CFLAGS += -I $(LIBFS_PREFIX)
     38CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
    3839
    39 LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
     40LIBS = \
     41        $(LIBC_PREFIX)/libc.a \
     42        $(LIBFS_PREFIX)/libfs.a \
     43        $(LIBBLOCK_PREFIX)/libblock.a
    4044
    4145## Sources
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    r04619ba rfc840d9  
    4646#include <sys/types.h>
    4747#include <as.h>
    48 #include <libfs.h>
     48#include <libblock.h>
    4949#include <ipc/services.h>
    5050#include <ipc/devmap.h>
     
    7171                uint32_t size;
    7272               
    73                 if (!libfs_blockread(phone, block, bufpos, buflen, pos, &entry,
     73                if (!blockread(phone, block, bufpos, buflen, pos, &entry,
    7474                    sizeof(entry), TMPFS_BLOCK_SIZE))
    7575                        return false;
     
    9191                        }
    9292                       
    93                         if (!libfs_blockread(phone, block, bufpos, buflen, pos,
    94                             fname, entry.len, TMPFS_BLOCK_SIZE)) {
     93                        if (!blockread(phone, block, bufpos, buflen, pos, fname,
     94                            entry.len, TMPFS_BLOCK_SIZE)) {
    9595                                ops->destroy((void *) node);
    9696                                free(fname);
     
    106106                        free(fname);
    107107                       
    108                         if (!libfs_blockread(phone, block, bufpos, buflen, pos,
    109                             &size, sizeof(size), TMPFS_BLOCK_SIZE))
     108                        if (!blockread(phone, block, bufpos, buflen, pos, &size,
     109                            sizeof(size), TMPFS_BLOCK_SIZE))
    110110                                return false;
    111111                       
     
    117117                       
    118118                        node->size = size;
    119                         if (!libfs_blockread(phone, block, bufpos, buflen, pos,
     119                        if (!blockread(phone, block, bufpos, buflen, pos,
    120120                            node->data, size, TMPFS_BLOCK_SIZE))
    121121                                return false;
     
    133133                        }
    134134                       
    135                         if (!libfs_blockread(phone, block, bufpos, buflen, pos,
    136                             fname, entry.len, TMPFS_BLOCK_SIZE)) {
     135                        if (!blockread(phone, block, bufpos, buflen, pos, fname,
     136                            entry.len, TMPFS_BLOCK_SIZE)) {
    137137                                ops->destroy((void *) node);
    138138                                free(fname);
     
    188188       
    189189        char tag[6];
    190         if (!libfs_blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
     190        if (!blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
    191191            TMPFS_BLOCK_SIZE))
    192192                goto error;
Note: See TracChangeset for help on using the changeset viewer.