Changes in / [056fa40:cffce57] in mainline


Ignore:
Files:
4 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    r056fa40 rcffce57  
    5252        $(USPACEDIR)/srv/fs/fat/fat \
    5353        $(USPACEDIR)/srv/bd/ata_bd/ata_bd \
    54         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    55         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     54        $(USPACEDIR)/srv/bd/file_bd/file_bd
    5655
    5756RD_APPS = \
  • boot/arch/arm32/loader/Makefile

    r056fa40 rcffce57  
    9393        $(USPACEDIR)/srv/fs/tmpfs/tmpfs \
    9494        $(USPACEDIR)/srv/fs/fat/fat \
    95         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    96         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     95        $(USPACEDIR)/srv/bd/file_bd/file_bd
    9796ifeq ($(MACHINE),testarm)
    9897        RD_SRVS += \
  • boot/arch/ia32/Makefile.inc

    r056fa40 rcffce57  
    5252        $(USPACEDIR)/srv/fs/fat/fat \
    5353        $(USPACEDIR)/srv/bd/ata_bd/ata_bd \
    54         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    55         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     54        $(USPACEDIR)/srv/bd/file_bd/file_bd
    5655
    5756RD_APPS = \
  • boot/arch/ia64/loader/Makefile

    r056fa40 rcffce57  
    104104        $(USPACEDIR)/srv/fs/tmpfs/tmpfs \
    105105        $(USPACEDIR)/srv/fs/fat/fat \
    106         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    107         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     106        $(USPACEDIR)/srv/bd/file_bd/file_bd
    108107
    109108RD_APPS = \
  • boot/arch/mips32/loader/Makefile

    r056fa40 rcffce57  
    106106        $(USPACEDIR)/srv/fs/fat/fat \
    107107        $(USPACEDIR)/srv/bd/file_bd/file_bd \
    108         $(USPACEDIR)/srv/bd/gxe_bd/gxe_bd \
    109         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     108        $(USPACEDIR)/srv/bd/gxe_bd/gxe_bd
    110109
    111110RD_APPS = \
  • boot/arch/ppc32/loader/Makefile

    r056fa40 rcffce57  
    9494        $(USPACEDIR)/srv/fs/tmpfs/tmpfs \
    9595        $(USPACEDIR)/srv/fs/fat/fat \
    96         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    97         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     96        $(USPACEDIR)/srv/bd/file_bd/file_bd
    9897
    9998RD_APPS = \
  • boot/arch/sparc64/loader/Makefile

    r056fa40 rcffce57  
    104104        $(USPACEDIR)/srv/fs/devfs/devfs \
    105105        $(USPACEDIR)/srv/fs/tmpfs/tmpfs \
    106         $(USPACEDIR)/srv/bd/file_bd/file_bd \
    107         $(USPACEDIR)/srv/part/mbr_part/mbr_part
     106        $(USPACEDIR)/srv/bd/file_bd/file_bd
    108107
    109108ifeq ($(MACHINE),generic)
  • kernel/arch/arm32/include/elf.h

    r056fa40 rcffce57  
    2727 */
    2828
    29 /** @addtogroup arm32
     29/** @addtogroup arm32   
    3030 * @{
    3131 */
     
    3737#define KERN_arm32_ELF_H_
    3838
    39 #define ELF_MACHINE  EM_ARM
     39#define ELF_MACHINE             EM_ARM
    4040
    41 #ifdef __BE__
    42         #define ELF_DATA_ENCODING  ELFDATA2MSB
     41#ifdef BIG_ENDIAN
     42#define ELF_DATA_ENCODING       ELFDATA2MSB
    4343#else
    44         #define ELF_DATA_ENCODING  ELFDATA2LSB
     44#define ELF_DATA_ENCODING       ELFDATA2LSB
    4545#endif
    4646
    47 #define ELF_CLASS  ELFCLASS32
     47#define ELF_CLASS               ELFCLASS32
    4848
    4949#endif
  • kernel/arch/ia64/include/atomic.h

    r056fa40 rcffce57  
    2727 */
    2828
    29 /** @addtogroup ia64
     29/** @addtogroup ia64   
    3030 * @{
    3131 */
     
    3636#define KERN_ia64_ATOMIC_H_
    3737
     38/** Atomic addition.
     39 *
     40 * @param val           Atomic value.
     41 * @param imm           Value to add.
     42 *
     43 * @return              Value before addition.
     44 */
     45static inline long atomic_add(atomic_t *val, int imm)
     46{
     47        long v;
     48
     49        asm volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v),
     50            "+m" (val->count) : "i" (imm));
     51 
     52        return v;
     53}
     54
    3855static inline uint64_t test_and_set(atomic_t *val)
    3956{
     
    4158               
    4259        asm volatile (
    43                 "movl %[v] = 0x1;;\n"
    44                 "xchg8 %[v] = %[count], %[v];;\n"
    45                 : [v] "=r" (v),
    46                   [count] "+m" (val->count)
     60                "movl %0 = 0x1;;\n"
     61                "xchg8 %0 = %1, %0;;\n"
     62                : "=r" (v), "+m" (val->count)
    4763        );
    4864       
     
    6076static inline void atomic_inc(atomic_t *val)
    6177{
    62         long v;
    63        
    64         asm volatile (
    65                 "fetchadd8.rel %[v] = %[count], 1\n"
    66                 : [v] "=r" (v),
    67                   [count] "+m" (val->count)
    68         );
     78        atomic_add(val, 1);
    6979}
    7080
    7181static inline void atomic_dec(atomic_t *val)
    7282{
    73         long v;
    74        
    75         asm volatile (
    76                 "fetchadd8.rel %[v] = %[count], -1\n"
    77                 : [v] "=r" (v),
    78                   [count] "+m" (val->count)
    79         );
     83        atomic_add(val, -1);
    8084}
    8185
    8286static inline long atomic_preinc(atomic_t *val)
    8387{
    84         long v;
    85        
    86         asm volatile (
    87                 "fetchadd8.rel %[v] = %[count], 1\n"
    88                 : [v] "=r" (v),
    89                   [count] "+m" (val->count)
    90         );
    91        
    92         return (v + 1);
     88        return atomic_add(val, 1) + 1;
    9389}
    9490
    9591static inline long atomic_predec(atomic_t *val)
    9692{
    97         long v;
    98        
    99         asm volatile (
    100                 "fetchadd8.rel %[v] = %[count], -1\n"
    101                 : [v] "=r" (v),
    102                   [count] "+m" (val->count)
    103         );
    104        
    105         return (v - 1);
     93        return atomic_add(val, -1) - 1;
    10694}
    10795
    10896static inline long atomic_postinc(atomic_t *val)
    10997{
    110         long v;
    111        
    112         asm volatile (
    113                 "fetchadd8.rel %[v] = %[count], 1\n"
    114                 : [v] "=r" (v),
    115                   [count] "+m" (val->count)
    116         );
    117        
    118         return v;
     98        return atomic_add(val, 1);
    11999}
    120100
    121101static inline long atomic_postdec(atomic_t *val)
    122102{
    123         long v;
    124        
    125         asm volatile (
    126                 "fetchadd8.rel %[v] = %[count], -1\n"
    127                 : [v] "=r" (v),
    128                   [count] "+m" (val->count)
    129         );
    130        
    131         return v;
     103        return atomic_add(val, -1);
    132104}
    133105
  • kernel/arch/mips32/include/mm/tlb.h

    r056fa40 rcffce57  
    5959typedef union {
    6060        struct {
    61 #ifdef __BE__
     61#ifdef BIG_ENDIAN
    6262                unsigned : 2;       /* zero */
    6363                unsigned pfn : 24;  /* frame number */
     
    8080typedef union {
    8181        struct {
    82 #ifdef __BE__
     82#ifdef BIG_ENDIAN
    8383                unsigned vpn2 : 19;
    8484                unsigned : 5;
     
    9595typedef union {
    9696        struct {
    97 #ifdef __BE__
     97#ifdef BIG_ENDIAN
    9898                unsigned : 7;
    9999                unsigned mask : 12;
     
    110110typedef union {
    111111        struct {
    112 #ifdef __BE__
     112#ifdef BIG_ENDIAN
    113113                unsigned p : 1;
    114114                unsigned : 27;
  • uspace/Makefile

    r056fa40 rcffce57  
    5252        srv/vfs \
    5353        srv/devmap \
    54         srv/part/mbr_part \
    5554        app/tetris \
    5655        app/tester \
  • uspace/lib/libblock/libblock.c

    r056fa40 rcffce57  
    5050#include <adt/list.h>
    5151#include <adt/hash_table.h>
    52 #include <macros.h>
    5352#include <mem.h>
    5453
     
    6362typedef struct {
    6463        fibril_mutex_t lock;
    65         size_t lblock_size;             /**< Logical block size. */
     64        size_t block_size;              /**< Block size. */
    6665        unsigned block_count;           /**< Total number of blocks. */
    6766        unsigned blocks_cached;         /**< Number of cached blocks. */
     
    7574        dev_handle_t dev_handle;
    7675        int dev_phone;
    77         fibril_mutex_t comm_area_lock;
    78         void *comm_area;
    79         size_t comm_size;
     76        fibril_mutex_t com_area_lock;
     77        void *com_area;
     78        size_t com_size;
    8079        void *bb_buf;
    81         bn_t bb_addr;
    82         size_t pblock_size;             /**< Physical block size. */
     80        off_t bb_off;
     81        size_t bb_size;
    8382        cache_t *cache;
    8483} devcon_t;
    8584
    86 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    87 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    88 static int get_block_size(int dev_phone, size_t *bsize);
     85static int read_block(devcon_t *devcon, bn_t boff, size_t block_size);
     86static int write_block(devcon_t *devcon, bn_t boff, size_t block_size);
    8987
    9088static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    104102}
    105103
    106 static int devcon_add(dev_handle_t dev_handle, int dev_phone, size_t bsize,
    107     void *comm_area, size_t comm_size)
     104static int devcon_add(dev_handle_t dev_handle, int dev_phone, void *com_area,
     105   size_t com_size)
    108106{
    109107        link_t *cur;
    110108        devcon_t *devcon;
    111 
    112         if (comm_size < bsize)
    113                 return EINVAL;
    114109
    115110        devcon = malloc(sizeof(devcon_t));
     
    120115        devcon->dev_handle = dev_handle;
    121116        devcon->dev_phone = dev_phone;
    122         fibril_mutex_initialize(&devcon->comm_area_lock);
    123         devcon->comm_area = comm_area;
    124         devcon->comm_size = comm_size;
     117        fibril_mutex_initialize(&devcon->com_area_lock);
     118        devcon->com_area = com_area;
     119        devcon->com_size = com_size;
    125120        devcon->bb_buf = NULL;
    126         devcon->bb_addr = 0;
    127         devcon->pblock_size = bsize;
     121        devcon->bb_off = 0;
     122        devcon->bb_size = 0;
    128123        devcon->cache = NULL;
    129124
     
    149144}
    150145
    151 int block_init(dev_handle_t dev_handle, size_t comm_size)
     146int block_init(dev_handle_t dev_handle, size_t com_size)
    152147{
    153148        int rc;
    154149        int dev_phone;
    155         void *comm_area;
    156         size_t bsize;
    157 
    158         comm_area = mmap(NULL, comm_size, PROTO_READ | PROTO_WRITE,
     150        void *com_area;
     151       
     152        com_area = mmap(NULL, com_size, PROTO_READ | PROTO_WRITE,
    159153            MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
    160         if (!comm_area) {
     154        if (!com_area) {
    161155                return ENOMEM;
    162156        }
     
    164158        dev_phone = devmap_device_connect(dev_handle, IPC_FLAG_BLOCKING);
    165159        if (dev_phone < 0) {
    166                 munmap(comm_area, comm_size);
     160                munmap(com_area, com_size);
    167161                return dev_phone;
    168162        }
    169163
    170         rc = ipc_share_out_start(dev_phone, comm_area,
     164        rc = ipc_share_out_start(dev_phone, com_area,
    171165            AS_AREA_READ | AS_AREA_WRITE);
    172166        if (rc != EOK) {
    173                 munmap(comm_area, comm_size);
     167                munmap(com_area, com_size);
    174168                ipc_hangup(dev_phone);
    175169                return rc;
    176170        }
    177 
    178         if (get_block_size(dev_phone, &bsize) != EOK) {
    179                 munmap(comm_area, comm_size);
    180                 ipc_hangup(dev_phone);
    181                 return rc;
    182         }
    183        
    184         rc = devcon_add(dev_handle, dev_phone, bsize, comm_area, comm_size);
     171       
     172        rc = devcon_add(dev_handle, dev_phone, com_area, com_size);
    185173        if (rc != EOK) {
    186                 munmap(comm_area, comm_size);
     174                munmap(com_area, com_size);
    187175                ipc_hangup(dev_phone);
    188176                return rc;
     
    207195        }
    208196
    209         munmap(devcon->comm_area, devcon->comm_size);
     197        munmap(devcon->com_area, devcon->com_size);
    210198        ipc_hangup(devcon->dev_phone);
    211199
     
    213201}
    214202
    215 int block_bb_read(dev_handle_t dev_handle, bn_t ba)
     203int block_bb_read(dev_handle_t dev_handle, off_t off, size_t size)
    216204{
    217205        void *bb_buf;
     
    223211        if (devcon->bb_buf)
    224212                return EEXIST;
    225         bb_buf = malloc(devcon->pblock_size);
     213        bb_buf = malloc(size);
    226214        if (!bb_buf)
    227215                return ENOMEM;
    228 
    229         fibril_mutex_lock(&devcon->comm_area_lock);
    230         rc = read_blocks(devcon, 0, 1);
     216       
     217        fibril_mutex_lock(&devcon->com_area_lock);
     218        rc = read_block(devcon, 0, size);
    231219        if (rc != EOK) {
    232                 fibril_mutex_unlock(&devcon->comm_area_lock);
     220                fibril_mutex_unlock(&devcon->com_area_lock);
    233221                free(bb_buf);
    234222                return rc;
    235223        }
    236         memcpy(bb_buf, devcon->comm_area, devcon->pblock_size);
    237         fibril_mutex_unlock(&devcon->comm_area_lock);
     224        memcpy(bb_buf, devcon->com_area, size);
     225        fibril_mutex_unlock(&devcon->com_area_lock);
    238226
    239227        devcon->bb_buf = bb_buf;
    240         devcon->bb_addr = ba;
     228        devcon->bb_off = off;
     229        devcon->bb_size = size;
    241230
    242231        return EOK;
     
    286275        fibril_mutex_initialize(&cache->lock);
    287276        list_initialize(&cache->free_head);
    288         cache->lblock_size = size;
     277        cache->block_size = size;
    289278        cache->block_count = blocks;
    290279        cache->blocks_cached = 0;
    291280        cache->mode = mode;
    292 
    293         /* No block size translation a.t.m. */
    294         assert(cache->lblock_size == devcon->pblock_size);
    295281
    296282        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    385371                        if (!b)
    386372                                goto recycle;
    387                         b->data = malloc(cache->lblock_size);
     373                        b->data = malloc(cache->block_size);
    388374                        if (!b->data) {
    389375                                free(b);
     
    419405                                list_append(&b->free_link, &cache->free_head);
    420406                                fibril_mutex_unlock(&cache->lock);
    421                                 fibril_mutex_lock(&devcon->comm_area_lock);
    422                                 memcpy(devcon->comm_area, b->data, b->size);
    423                                 rc = write_blocks(devcon, b->boff, 1);
    424                                 fibril_mutex_unlock(&devcon->comm_area_lock);
     407                                fibril_mutex_lock(&devcon->com_area_lock);
     408                                memcpy(devcon->com_area, b->data, b->size);
     409                                rc = write_block(devcon, b->boff,
     410                                    cache->block_size);
     411                                fibril_mutex_unlock(&devcon->com_area_lock);
    425412                                if (rc != EOK) {
    426413                                        /*
     
    457444                block_initialize(b);
    458445                b->dev_handle = dev_handle;
    459                 b->size = cache->lblock_size;
     446                b->size = cache->block_size;
    460447                b->boff = boff;
    461448                hash_table_insert(&cache->block_hash, &key, &b->hash_link);
     
    474461                         * the new contents from the device.
    475462                         */
    476                         fibril_mutex_lock(&devcon->comm_area_lock);
    477                         rc = read_blocks(devcon, b->boff, 1);
    478                         memcpy(b->data, devcon->comm_area, cache->lblock_size);
    479                         fibril_mutex_unlock(&devcon->comm_area_lock);
     463                        fibril_mutex_lock(&devcon->com_area_lock);
     464                        rc = read_block(devcon, b->boff, cache->block_size);
     465                        memcpy(b->data, devcon->com_area, cache->block_size);
     466                        fibril_mutex_unlock(&devcon->com_area_lock);
    480467                        if (rc != EOK)
    481468                                b->toxic = true;
     
    534521        if (block->dirty && (block->refcnt == 1) &&
    535522            (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) {
    536                 fibril_mutex_lock(&devcon->comm_area_lock);
    537                 memcpy(devcon->comm_area, block->data, block->size);
    538                 rc = write_blocks(devcon, block->boff, 1);
    539                 fibril_mutex_unlock(&devcon->comm_area_lock);
     523                fibril_mutex_lock(&devcon->com_area_lock);
     524                memcpy(devcon->com_area, block->data, block->size);
     525                rc = write_block(devcon, block->boff, block->size);
     526                fibril_mutex_unlock(&devcon->com_area_lock);
    540527                block->dirty = false;
    541528        }
     
    614601 */
    615602int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
    616     off_t *pos, void *dst, size_t size)
     603    off_t *pos, void *dst, size_t size, size_t block_size)
    617604{
    618605        off_t offset = 0;
    619606        size_t left = size;
    620         size_t block_size;
    621         devcon_t *devcon;
    622 
    623         devcon = devcon_search(dev_handle);
     607        devcon_t *devcon = devcon_search(dev_handle);
    624608        assert(devcon);
    625         block_size = devcon->pblock_size;
    626        
    627         fibril_mutex_lock(&devcon->comm_area_lock);
     609       
     610        fibril_mutex_lock(&devcon->com_area_lock);
    628611        while (left > 0) {
    629612                size_t rd;
     
    639622                         * destination buffer.
    640623                         */
    641                         memcpy(dst + offset, devcon->comm_area + *bufpos, rd);
     624                        memcpy(dst + offset, devcon->com_area + *bufpos, rd);
    642625                        offset += rd;
    643626                        *bufpos += rd;
     
    650633                        int rc;
    651634
    652                         rc = read_blocks(devcon, *pos / block_size, 1);
     635                        rc = read_block(devcon, *pos / block_size, block_size);
    653636                        if (rc != EOK) {
    654                                 fibril_mutex_unlock(&devcon->comm_area_lock);
     637                                fibril_mutex_unlock(&devcon->com_area_lock);
    655638                                return rc;
    656639                        }
     
    660643                }
    661644        }
    662         fibril_mutex_unlock(&devcon->comm_area_lock);
     645        fibril_mutex_unlock(&devcon->com_area_lock);
    663646       
    664647        return EOK;
    665648}
    666649
    667 /** Read blocks directly from device (bypass cache).
    668  *
    669  * @param dev_handle    Device handle of the block device.
    670  * @param ba            Address of first block.
    671  * @param cnt           Number of blocks.
     650/** Read block from block device.
     651 *
     652 * @param devcon        Device connection.
     653 * @param boff          Block index.
     654 * @param block_size    Block size.
    672655 * @param src           Buffer for storing the data.
    673656 *
    674657 * @return              EOK on success or negative error code on failure.
    675658 */
    676 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)
    677 {
    678         devcon_t *devcon;
     659static int read_block(devcon_t *devcon, bn_t boff, size_t block_size)
     660{
     661        ipcarg_t retval;
    679662        int rc;
    680663
    681         devcon = devcon_search(dev_handle);
    682664        assert(devcon);
    683        
    684         fibril_mutex_lock(&devcon->comm_area_lock);
    685 
    686         rc = read_blocks(devcon, ba, cnt);
    687         if (rc == EOK)
    688                 memcpy(buf, devcon->comm_area, devcon->pblock_size * cnt);
    689 
    690         fibril_mutex_unlock(&devcon->comm_area_lock);
    691 
    692         return rc;
    693 }
    694 
    695 /** Write blocks directly to device (bypass cache).
    696  *
    697  * @param dev_handle    Device handle of the block device.
    698  * @param ba            Address of first block.
    699  * @param cnt           Number of blocks.
    700  * @param src           The data to be written.
     665        rc = async_req_2_1(devcon->dev_phone, BD_READ_BLOCK, boff, block_size,
     666            &retval);
     667        if ((rc != EOK) || (retval != EOK))
     668                return (rc != EOK ? rc : (int) retval);
     669
     670        return EOK;
     671}
     672
     673/** Write block to block device.
     674 *
     675 * @param devcon        Device connection.
     676 * @param boff          Block index.
     677 * @param block_size    Block size.
     678 * @param src           Buffer containing the data to write.
    701679 *
    702680 * @return              EOK on success or negative error code on failure.
    703681 */
    704 int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt,
    705     const void *data)
    706 {
    707         devcon_t *devcon;
     682static int write_block(devcon_t *devcon, bn_t boff, size_t block_size)
     683{
     684        ipcarg_t retval;
    708685        int rc;
    709686
    710         devcon = devcon_search(dev_handle);
    711687        assert(devcon);
    712        
    713         fibril_mutex_lock(&devcon->comm_area_lock);
    714 
    715         memcpy(devcon->comm_area, data, devcon->pblock_size * cnt);
    716         rc = read_blocks(devcon, ba, cnt);
    717 
    718         fibril_mutex_unlock(&devcon->comm_area_lock);
    719 
    720         return rc;
    721 }
    722 
    723 /** Get device block size.
    724  *
    725  * @param dev_handle    Device handle of the block device.
    726  * @param bsize         Output block size.
    727  *
    728  * @return              EOK on success or negative error code on failure.
    729  */
    730 int block_get_bsize(dev_handle_t dev_handle, size_t *bsize)
    731 {
    732         devcon_t *devcon;
    733 
    734         devcon = devcon_search(dev_handle);
    735         assert(devcon);
    736        
    737         return get_block_size(devcon->dev_phone, bsize);
    738 }
    739 
    740 /** Read blocks from block device.
    741  *
    742  * @param devcon        Device connection.
    743  * @param ba            Address of first block.
    744  * @param cnt           Number of blocks.
    745  * @param src           Buffer for storing the data.
    746  *
    747  * @return              EOK on success or negative error code on failure.
    748  */
    749 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
    750 {
    751         int rc;
    752 
    753         assert(devcon);
    754         rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba),
    755             UPPER32(ba), cnt);
    756         return rc;
    757 }
    758 
    759 /** Write block to block device.
    760  *
    761  * @param devcon        Device connection.
    762  * @param ba            Address of first block.
    763  * @param cnt           Number of blocks.
    764  * @param src           Buffer containing the data to write.
    765  *
    766  * @return              EOK on success or negative error code on failure.
    767  */
    768 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
    769 {
    770         int rc;
    771 
    772         assert(devcon);
    773         rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba),
    774             UPPER32(ba), cnt);
    775         return rc;
    776 }
    777 
    778 /** Get block size used by the device. */
    779 static int get_block_size(int dev_phone, size_t *bsize)
    780 {
    781         ipcarg_t bs;
    782         int rc;
    783 
    784         rc = async_req_0_1(dev_phone, BD_GET_BLOCK_SIZE, &bs);
    785         if (rc == EOK)
    786                 *bsize = (size_t) bs;
    787 
    788         return rc;
     688        rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK, boff, block_size,
     689            &retval);
     690        if ((rc != EOK) || (retval != EOK))
     691                return (rc != EOK ? rc : (int) retval);
     692
     693        return EOK;
    789694}
    790695
  • uspace/lib/libblock/libblock.h

    r056fa40 rcffce57  
    6060#define BLOCK_FLAGS_NOREAD      1
    6161
    62 typedef uint64_t bn_t;  /**< Block number type. */
     62typedef unsigned bn_t;  /**< Block number type. */
    6363
    6464typedef struct block {
     
    9898extern void block_fini(dev_handle_t);
    9999
    100 extern int block_bb_read(dev_handle_t, bn_t);
     100extern int block_bb_read(dev_handle_t, off_t, size_t);
    101101extern void *block_bb_get(dev_handle_t);
    102102
     
    107107
    108108extern int block_seqread(dev_handle_t, off_t *, size_t *, off_t *, void *,
    109     size_t);
    110 
    111 extern int block_get_bsize(dev_handle_t, size_t *);
    112 extern int block_read_direct(dev_handle_t, bn_t, size_t, void *);
    113 extern int block_write_direct(dev_handle_t, bn_t, size_t, const void *);
     109    size_t, size_t);
    114110
    115111#endif
  • uspace/lib/libc/arch/ia64/include/atomic.h

    r056fa40 rcffce57  
    2727 */
    2828
    29 /** @addtogroup libcia64
     29/** @addtogroup libcia64       
    3030 * @{
    3131 */
     
    3636#define LIBC_ia64_ATOMIC_H_
    3737
    38 static inline void atomic_inc(atomic_t *val)
     38/** Atomic addition.
     39 *
     40 * @param val Atomic value.
     41 * @param imm Value to add.
     42 *
     43 * @return Value before addition.
     44 */
     45static inline long atomic_add(atomic_t *val, int imm)
    3946{
    4047        long v;
    41        
    42         asm volatile (
    43                 "fetchadd8.rel %[v] = %[count], 1\n"
    44                 : [v] "=r" (v),
    45                   [count] "+m" (val->count)
    46         );
    47 }
    4848
    49 static inline void atomic_dec(atomic_t *val)
    50 {
    51         long v;
    52        
    53         asm volatile (
    54                 "fetchadd8.rel %[v] = %[count], -1\n"
    55                 : [v] "=r" (v),
    56                   [count] "+m" (val->count)
    57         );
    58 }
    59 
    60 static inline long atomic_preinc(atomic_t *val)
    61 {
    62         long v;
    63        
    64         asm volatile (
    65                 "fetchadd8.rel %[v] = %[count], 1\n"
    66                 : [v] "=r" (v),
    67                   [count] "+m" (val->count)
    68         );
    69        
    70         return (v + 1);
    71 }
    72 
    73 static inline long atomic_predec(atomic_t *val)
    74 {
    75         long v;
    76        
    77         asm volatile (
    78                 "fetchadd8.rel %[v] = %[count], -1\n"
    79                 : [v] "=r" (v),
    80                   [count] "+m" (val->count)
    81         );
    82        
    83         return (v - 1);
    84 }
    85 
    86 static inline long atomic_postinc(atomic_t *val)
    87 {
    88         long v;
    89        
    90         asm volatile (
    91                 "fetchadd8.rel %[v] = %[count], 1\n"
    92                 : [v] "=r" (v),
    93                   [count] "+m" (val->count)
    94         );
    95        
     49        asm volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v), "+m" (val->count) : "i" (imm));
     50 
    9651        return v;
    9752}
    9853
    99 static inline long atomic_postdec(atomic_t *val)
    100 {
    101         long v;
    102        
    103         asm volatile (
    104                 "fetchadd8.rel %[v] = %[count], -1\n"
    105                 : [v] "=r" (v),
    106                   [count] "+m" (val->count)
    107         );
    108        
    109         return v;
    110 }
     54static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
     55static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
     56
     57static inline long atomic_preinc(atomic_t *val) { return atomic_add(val, 1) + 1; }
     58static inline long atomic_predec(atomic_t *val) { return atomic_add(val, -1) - 1; }
     59
     60static inline long atomic_postinc(atomic_t *val) { return atomic_add(val, 1); }
     61static inline long atomic_postdec(atomic_t *val) { return atomic_add(val, -1); }
    11162
    11263#endif
  • uspace/lib/libc/include/ipc/bd.h

    r056fa40 rcffce57  
    3939
    4040typedef enum {
    41         BD_GET_BLOCK_SIZE = IPC_FIRST_USER_METHOD,
    42         BD_READ_BLOCKS,
    43         BD_WRITE_BLOCKS
     41        BD_READ_BLOCK = IPC_FIRST_USER_METHOD,
     42        BD_WRITE_BLOCK
    4443} bd_request_t;
    4544
  • uspace/srv/bd/ata_bd/ata_bd.c

    r056fa40 rcffce57  
    6262#include <bool.h>
    6363#include <task.h>
    64 #include <macros.h>
    6564
    6665#include "ata_bd.h"
     
    8786static int ata_bd_init(void);
    8887static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
    89 static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt,
     88static int ata_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
    9089    void *buf);
    91 static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
    92     const void *buf);
    93 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t cnt,
     90static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
    9491    void *buf);
    95 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     92static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
    9693    const void *buf);
    9794static int disk_init(disk_t *d, int disk_id);
    9895static int drive_identify(int drive_id, void *buf);
    9996static void disk_print_summary(disk_t *d);
    100 static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc);
     97static int coord_calc(disk_t *d, uint64_t blk_idx, block_coord_t *bc);
    10198static void coord_sc_program(const block_coord_t *bc, uint16_t scnt);
    10299static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus,
     
    231228        int flags;
    232229        int retval;
    233         uint64_t ba;
    234         size_t cnt;
     230        off_t idx;
     231        size_t size;
    235232        int disk_id, i;
    236233
     
    273270                        ipc_answer_0(callid, EOK);
    274271                        return;
    275                 case BD_READ_BLOCKS:
    276                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    277                             IPC_GET_ARG2(call));
    278                         cnt = IPC_GET_ARG3(call);
    279                         if (cnt * block_size > comm_size) {
    280                                 retval = ELIMIT;
     272                case BD_READ_BLOCK:
     273                case BD_WRITE_BLOCK:
     274                        idx = IPC_GET_ARG1(call);
     275                        size = IPC_GET_ARG2(call);
     276                        if (size > comm_size) {
     277                                retval = EINVAL;
    281278                                break;
    282279                        }
    283                         retval = ata_bd_read_blocks(disk_id, ba, cnt, fs_va);
     280                        retval = ata_bd_rdwr(disk_id, method, idx,
     281                            size, fs_va);
    284282                        break;
    285                 case BD_WRITE_BLOCKS:
    286                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    287                             IPC_GET_ARG2(call));
    288                         cnt = IPC_GET_ARG3(call);
    289                         if (cnt * block_size > comm_size) {
    290                                 retval = ELIMIT;
    291                                 break;
    292                         }
    293                         retval = ata_bd_write_blocks(disk_id, ba, cnt, fs_va);
    294                         break;
    295                 case BD_GET_BLOCK_SIZE:
    296                         ipc_answer_1(callid, EOK, block_size);
    297                         continue;
    298283                default:
    299284                        retval = EINVAL;
     
    388373}
    389374
    390 /** Read multiple blocks from the device. */
    391 static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt,
    392     void *buf) {
    393 
     375/** Transfer a logical block from/to the device.
     376 *
     377 * @param disk_id       Device index (0 or 1)
     378 * @param method        @c BD_READ_BLOCK or @c BD_WRITE_BLOCK
     379 * @param blk_idx       Index of the first block.
     380 * @param size          Size of the logical block.
     381 * @param buf           Data buffer.
     382 *
     383 * @return EOK on success, EIO on error.
     384 */
     385static int ata_bd_rdwr(int disk_id, ipcarg_t method, off_t blk_idx, size_t size,
     386    void *buf)
     387{
    394388        int rc;
    395 
    396         while (cnt > 0) {
    397                 rc = ata_bd_read_block(disk_id, ba, 1, buf);
     389        size_t now;
     390
     391        while (size > 0) {
     392                now = size < block_size ? size : block_size;
     393                if (now != block_size)
     394                        return EINVAL;
     395
     396                if (method == BD_READ_BLOCK)
     397                        rc = ata_bd_read_block(disk_id, blk_idx, 1, buf);
     398                else
     399                        rc = ata_bd_write_block(disk_id, blk_idx, 1, buf);
     400
    398401                if (rc != EOK)
    399402                        return rc;
    400403
    401                 ++ba;
    402                 --cnt;
    403404                buf += block_size;
    404         }
    405 
    406         return EOK;
    407 }
    408 
    409 /** Write multiple blocks to the device. */
    410 static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
    411     const void *buf) {
    412 
    413         int rc;
    414 
    415         while (cnt > 0) {
    416                 rc = ata_bd_write_block(disk_id, ba, 1, buf);
    417                 if (rc != EOK)
    418                         return rc;
    419 
    420                 ++ba;
    421                 --cnt;
    422                 buf += block_size;
     405                blk_idx++;
     406
     407                if (size > block_size)
     408                        size -= block_size;
     409                else
     410                        size = 0;
    423411        }
    424412
     
    478466 *
    479467 * @param disk_id       Device index (0 or 1)
    480  * @param ba            Address the first block.
    481  * @param cnt           Number of blocks to transfer.
     468 * @param blk_idx       Index of the first block.
     469 * @param blk_cnt       Number of blocks to transfer.
    482470 * @param buf           Buffer for holding the data.
    483471 *
    484472 * @return EOK on success, EIO on error.
    485473 */
    486 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t blk_cnt,
     474static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
    487475    void *buf)
    488476{
     
    498486
    499487        /* Compute block coordinates. */
    500         if (coord_calc(d, ba, &bc) != EOK)
     488        if (coord_calc(d, blk_idx, &bc) != EOK)
    501489                return EINVAL;
    502490
     
    553541 *
    554542 * @param disk_id       Device index (0 or 1)
    555  * @param ba            Address of the first block.
    556  * @param cnt           Number of blocks to transfer.
     543 * @param blk_idx       Index of the first block.
     544 * @param blk_cnt       Number of blocks to transfer.
    557545 * @param buf           Buffer holding the data to write.
    558546 *
    559547 * @return EOK on success, EIO on error.
    560548 */
    561 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     549static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt,
    562550    const void *buf)
    563551{
     
    572560
    573561        /* Compute block coordinates. */
    574         if (coord_calc(d, ba, &bc) != EOK)
     562        if (coord_calc(d, blk_idx, &bc) != EOK)
    575563                return EINVAL;
    576564
     
    632620 * @return EOK on success or EINVAL if block index is past end of device.
    633621 */
    634 static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc)
     622static int coord_calc(disk_t *d, uint64_t blk_idx, block_coord_t *bc)
    635623{
    636624        uint64_t c;
     
    638626
    639627        /* Check device bounds. */
    640         if (ba >= d->blocks)
     628        if (blk_idx >= d->blocks)
    641629                return EINVAL;
    642630
     
    646634        case am_chs:
    647635                /* Compute CHS coordinates. */
    648                 c = ba / (d->geom.heads * d->geom.sectors);
    649                 idx = ba % (d->geom.heads * d->geom.sectors);
     636                c = blk_idx / (d->geom.heads * d->geom.sectors);
     637                idx = blk_idx % (d->geom.heads * d->geom.sectors);
    650638
    651639                bc->cyl_lo = c & 0xff;
     
    657645        case am_lba28:
    658646                /* Compute LBA-28 coordinates. */
    659                 bc->c0 = ba & 0xff;             /* bits 0-7 */
    660                 bc->c1 = (ba >> 8) & 0xff;      /* bits 8-15 */
    661                 bc->c2 = (ba >> 16) & 0xff;     /* bits 16-23 */
    662                 bc->h  = (ba >> 24) & 0x0f;     /* bits 24-27 */
     647                bc->c0 = blk_idx & 0xff;                /* bits 0-7 */
     648                bc->c1 = (blk_idx >> 8) & 0xff;         /* bits 8-15 */
     649                bc->c2 = (blk_idx >> 16) & 0xff;        /* bits 16-23 */
     650                bc->h  = (blk_idx >> 24) & 0x0f;        /* bits 24-27 */
    663651                break;
    664652
    665653        case am_lba48:
    666654                /* Compute LBA-48 coordinates. */
    667                 bc->c0 = ba & 0xff;             /* bits 0-7 */
    668                 bc->c1 = (ba >> 8) & 0xff;      /* bits 8-15 */
    669                 bc->c2 = (ba >> 16) & 0xff;     /* bits 16-23 */
    670                 bc->c3 = (ba >> 24) & 0xff;     /* bits 24-31 */
    671                 bc->c4 = (ba >> 32) & 0xff;     /* bits 32-39 */
    672                 bc->c5 = (ba >> 40) & 0xff;     /* bits 40-47 */
     655                bc->c0 = blk_idx & 0xff;                /* bits 0-7 */
     656                bc->c1 = (blk_idx >> 8) & 0xff;         /* bits 8-15 */
     657                bc->c2 = (blk_idx >> 16) & 0xff;        /* bits 16-23 */
     658                bc->c3 = (blk_idx >> 24) & 0xff;        /* bits 24-31 */
     659                bc->c4 = (blk_idx >> 32) & 0xff;        /* bits 32-39 */
     660                bc->c5 = (blk_idx >> 40) & 0xff;        /* bits 40-47 */
    673661                bc->h  = 0;
    674662                break;
  • uspace/srv/bd/file_bd/file_bd.c

    r056fa40 rcffce57  
    5151#include <bool.h>
    5252#include <task.h>
    53 #include <macros.h>
    5453
    5554#define NAME "file_bd"
    5655
    57 static const size_t block_size = 512;
     56static size_t comm_size;
    5857static FILE *img;
    5958
     
    6362static int file_bd_init(const char *fname);
    6463static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
    65 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf);
    66 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
     64static int file_bd_read(off_t blk_idx, size_t size, void *buf);
     65static int file_bd_write(off_t blk_idx, size_t size, void *buf);
    6766
    6867int main(int argc, char **argv)
     
    121120        ipc_call_t call;
    122121        ipcarg_t method;
    123         size_t comm_size;
    124122        int flags;
    125123        int retval;
    126         uint64_t ba;
    127         size_t cnt;
     124        off_t idx;
     125        size_t size;
    128126
    129127        /* Answer the IPC_M_CONNECT_ME_TO call. */
     
    151149                        ipc_answer_0(callid, EOK);
    152150                        return;
    153                 case BD_READ_BLOCKS:
    154                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    155                             IPC_GET_ARG2(call));
    156                         cnt = IPC_GET_ARG3(call);
    157                         if (cnt * block_size > comm_size) {
    158                                 retval = ELIMIT;
     151                case BD_READ_BLOCK:
     152                case BD_WRITE_BLOCK:
     153                        idx = IPC_GET_ARG1(call);
     154                        size = IPC_GET_ARG2(call);
     155                        if (size > comm_size) {
     156                                retval = EINVAL;
    159157                                break;
    160158                        }
    161                         retval = file_bd_read_blocks(ba, cnt, fs_va);
     159                        if (method == BD_READ_BLOCK)
     160                                retval = file_bd_read(idx, size, fs_va);
     161                        else
     162                                retval = file_bd_write(idx, size, fs_va);
    162163                        break;
    163                 case BD_WRITE_BLOCKS:
    164                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    165                             IPC_GET_ARG2(call));
    166                         cnt = IPC_GET_ARG3(call);
    167                         if (cnt * block_size > comm_size) {
    168                                 retval = ELIMIT;
    169                                 break;
    170                         }
    171                         retval = file_bd_write_blocks(ba, cnt, fs_va);
    172                         break;
    173                 case BD_GET_BLOCK_SIZE:
    174                         ipc_answer_1(callid, EOK, block_size);
    175                         continue;
    176164                default:
    177165                        retval = EINVAL;
     
    182170}
    183171
    184 /** Read blocks from the device. */
    185 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf)
     172static int file_bd_read(off_t blk_idx, size_t size, void *buf)
    186173{
    187174        size_t n_rd;
     
    189176        fibril_mutex_lock(&dev_lock);
    190177
    191         fseek(img, ba * block_size, SEEK_SET);
    192         n_rd = fread(buf, block_size, cnt, img);
     178        fseek(img, blk_idx * size, SEEK_SET);
     179        n_rd = fread(buf, 1, size, img);
    193180
    194181        if (ferror(img)) {
     
    199186        fibril_mutex_unlock(&dev_lock);
    200187
    201         if (n_rd < cnt)
    202                 return EINVAL;  /* Read beyond end of device */
     188        if (n_rd < size)
     189                return EINVAL;  /* Read beyond end of disk */
    203190
    204191        return EOK;
    205192}
    206193
    207 /** Write blocks to the device. */
    208 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf)
     194static int file_bd_write(off_t blk_idx, size_t size, void *buf)
    209195{
    210196        size_t n_wr;
     
    212198        fibril_mutex_lock(&dev_lock);
    213199
    214         fseek(img, ba * block_size, SEEK_SET);
    215         n_wr = fread(buf, block_size, cnt, img);
    216 
    217         if (ferror(img) || n_wr < cnt) {
     200        fseek(img, blk_idx * size, SEEK_SET);
     201        n_wr = fread(buf, 1, size, img);
     202
     203        if (ferror(img) || n_wr < size) {
    218204                fibril_mutex_unlock(&dev_lock);
    219205                return EIO;     /* Write error */
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    r056fa40 rcffce57  
    4747#include <sys/types.h>
    4848#include <errno.h>
    49 #include <macros.h>
    5049#include <task.h>
    5150
     
    9897static int gxe_bd_init(void);
    9998static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
    100 static int gxe_bd_read_blocks(int disk_id, uint64_t ba, unsigned cnt,
     99static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
    101100    void *buf);
    102 static int gxe_bd_write_blocks(int disk_id, uint64_t ba, unsigned cnt,
     101static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
     102    void *buf);
     103static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
    103104    const void *buf);
    104 static int gxe_bd_read_block(int disk_id, uint64_t ba, void *buf);
    105 static int gxe_bd_write_block(int disk_id, uint64_t ba, const void *buf);
    106105
    107106int main(int argc, char **argv)
     
    164163        int flags;
    165164        int retval;
    166         uint64_t ba;
    167         unsigned cnt;
     165        off_t idx;
     166        size_t size;
    168167        int disk_id, i;
    169168
     
    186185
    187186        if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
    188                 ipc_answer_0(callid, EHANGUP);
    189                 return;
    190         }
    191 
    192         if (comm_size < block_size) {
    193187                ipc_answer_0(callid, EHANGUP);
    194188                return;
     
    211205                        ipc_answer_0(callid, EOK);
    212206                        return;
    213                 case BD_READ_BLOCKS:
    214                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    215                             IPC_GET_ARG2(call));
    216                         cnt = IPC_GET_ARG3(call);
    217                         if (cnt * block_size > comm_size) {
    218                                 retval = ELIMIT;
     207                case BD_READ_BLOCK:
     208                case BD_WRITE_BLOCK:
     209                        idx = IPC_GET_ARG1(call);
     210                        size = IPC_GET_ARG2(call);
     211                        if (size > comm_size) {
     212                                retval = EINVAL;
    219213                                break;
    220214                        }
    221                         retval = gxe_bd_read_blocks(disk_id, ba, cnt, fs_va);
     215                        retval = gx_bd_rdwr(disk_id, method, idx * size,
     216                            size, fs_va);
    222217                        break;
    223                 case BD_WRITE_BLOCKS:
    224                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    225                             IPC_GET_ARG2(call));
    226                         cnt = IPC_GET_ARG3(call);
    227                         if (cnt * block_size > comm_size) {
    228                                 retval = ELIMIT;
    229                                 break;
    230                         }
    231                         retval = gxe_bd_write_blocks(disk_id, ba, cnt, fs_va);
    232                         break;
    233                 case BD_GET_BLOCK_SIZE:
    234                         ipc_answer_1(callid, EOK, block_size);
    235                         continue;
    236218                default:
    237219                        retval = EINVAL;
     
    242224}
    243225
    244 /** Read multiple blocks from the device. */
    245 static int gxe_bd_read_blocks(int disk_id, uint64_t ba, unsigned cnt,
    246     void *buf) {
    247 
     226static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
     227    void *buf)
     228{
    248229        int rc;
    249 
    250         while (cnt > 0) {
    251                 rc = gxe_bd_read_block(disk_id, ba, buf);
     230        size_t now;
     231
     232        while (size > 0) {
     233                now = size < block_size ? size : block_size;
     234
     235                if (method == BD_READ_BLOCK)
     236                        rc = gxe_bd_read_block(disk_id, offset, now, buf);
     237                else
     238                        rc = gxe_bd_write_block(disk_id, offset, now, buf);
     239
    252240                if (rc != EOK)
    253241                        return rc;
    254242
    255                 ++ba;
    256                 --cnt;
    257243                buf += block_size;
     244                offset += block_size;
     245
     246                if (size > block_size)
     247                        size -= block_size;
     248                else
     249                        size = 0;
    258250        }
    259251
     
    261253}
    262254
    263 /** Write multiple blocks to the device. */
    264 static int gxe_bd_write_blocks(int disk_id, uint64_t ba, unsigned cnt,
    265     const void *buf) {
    266 
    267         int rc;
    268 
    269         while (cnt > 0) {
    270                 rc = gxe_bd_write_block(disk_id, ba, buf);
    271                 if (rc != EOK)
    272                         return rc;
    273 
    274                 ++ba;
    275                 --cnt;
    276                 buf += block_size;
    277         }
    278 
    279         return EOK;
    280 }
    281 
    282 /** Read a block from the device. */
    283 static int gxe_bd_read_block(int disk_id, uint64_t ba, void *buf)
     255static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
     256    void *buf)
    284257{
    285258        uint32_t status;
    286         uint64_t byte_addr;
    287259        size_t i;
    288260        uint32_t w;
    289261
    290         byte_addr = ba * block_size;
    291 
    292262        fibril_mutex_lock(&dev_lock[disk_id]);
    293         pio_write_32(&dev->offset_lo, (uint32_t) byte_addr);
    294         pio_write_32(&dev->offset_hi, byte_addr >> 32);
     263        pio_write_32(&dev->offset_lo, (uint32_t) offset);
     264        pio_write_32(&dev->offset_hi, offset >> 32);
    295265        pio_write_32(&dev->disk_id, disk_id);
    296266        pio_write_32(&dev->control, CTL_READ_START);
     
    302272        }
    303273
    304         for (i = 0; i < block_size; i++) {
     274        for (i = 0; i < size; i++) {
    305275                ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
    306276        }
     
    310280}
    311281
    312 /** Write a block to the device. */
    313 static int gxe_bd_write_block(int disk_id, uint64_t ba, const void *buf)
     282static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
     283    const void *buf)
    314284{
    315285        uint32_t status;
    316         uint64_t byte_addr;
    317286        size_t i;
    318287
    319         byte_addr = ba * block_size;
     288        for (i = 0; i < size; i++) {
     289                pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
     290        }
    320291
    321292        fibril_mutex_lock(&dev_lock[disk_id]);
    322 
    323         for (i = 0; i < block_size; i++) {
    324                 pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
    325         }
    326 
    327         pio_write_32(&dev->offset_lo, (uint32_t) byte_addr);
    328         pio_write_32(&dev->offset_hi, byte_addr >> 32);
     293        pio_write_32(&dev->offset_lo, (uint32_t) offset);
     294        pio_write_32(&dev->offset_hi, offset >> 32);
    329295        pio_write_32(&dev->disk_id, disk_id);
    330296        pio_write_32(&dev->control, CTL_WRITE_START);
  • uspace/srv/bd/rd/rd.c

    r056fa40 rcffce57  
    5555#include <devmap.h>
    5656#include <ipc/bd.h>
    57 #include <macros.h>
    5857
    5958#define NAME "rd"
    6059
    61 /** Pointer to the ramdisk's image */
     60/** Pointer to the ramdisk's image. */
    6261static void *rd_addr;
    63 /** Size of the ramdisk */
     62/** Size of the ramdisk. */
    6463static size_t rd_size;
    65 
    66 /** Block size */
    67 static const size_t block_size = 512;
    68 
    69 static int rd_read_blocks(uint64_t ba, size_t cnt, void *buf);
    70 static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
    7164
    7265/**
     
    8982        int retval;
    9083        void *fs_va = NULL;
    91         uint64_t ba;
    92         size_t cnt;
    93         size_t comm_size;
     84        off_t offset;
     85        size_t block_size;
     86        size_t maxblock_size;
    9487
    9588        /*
     
    10295         */
    10396        int flags;
    104         if (ipc_share_out_receive(&callid, &comm_size, &flags)) {
    105                 fs_va = as_get_mappable_page(comm_size);
     97        if (ipc_share_out_receive(&callid, &maxblock_size, &flags)) {
     98                fs_va = as_get_mappable_page(maxblock_size);
    10699                if (fs_va) {
    107100                        (void) ipc_share_out_finalize(callid, fs_va);
     
    130123                        ipc_answer_0(callid, EOK);
    131124                        return;
    132                 case BD_READ_BLOCKS:
    133                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    134                             IPC_GET_ARG2(call));
    135                         cnt = IPC_GET_ARG3(call);
    136                         if (cnt * block_size > comm_size) {
    137                                 retval = ELIMIT;
    138                                 break;
    139                         }
    140                         retval = rd_read_blocks(ba, cnt, fs_va);
     125                case BD_READ_BLOCK:
     126                        offset = IPC_GET_ARG1(call);
     127                        block_size = IPC_GET_ARG2(call);
     128                        if (block_size > maxblock_size) {
     129                                /*
     130                                 * Maximum block size exceeded.
     131                                 */
     132                                retval = ELIMIT;
     133                                break;
     134                        }
     135                        if (offset * block_size > rd_size - block_size) {
     136                                /*
     137                                 * Reading past the end of the device.
     138                                 */
     139                                retval = ELIMIT;
     140                                break;
     141                        }
     142                        fibril_rwlock_read_lock(&rd_lock);
     143                        memcpy(fs_va, rd_addr + offset * block_size, block_size);
     144                        fibril_rwlock_read_unlock(&rd_lock);
     145                        retval = EOK;
    141146                        break;
    142                 case BD_WRITE_BLOCKS:
    143                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    144                             IPC_GET_ARG2(call));
    145                         cnt = IPC_GET_ARG3(call);
    146                         if (cnt * block_size > comm_size) {
    147                                 retval = ELIMIT;
    148                                 break;
    149                         }
    150                         retval = rd_write_blocks(ba, cnt, fs_va);
     147                case BD_WRITE_BLOCK:
     148                        offset = IPC_GET_ARG1(call);
     149                        block_size = IPC_GET_ARG2(call);
     150                        if (block_size > maxblock_size) {
     151                                /*
     152                                 * Maximum block size exceeded.
     153                                 */
     154                                retval = ELIMIT;
     155                                break;
     156                        }
     157                        if (offset * block_size > rd_size - block_size) {
     158                                /*
     159                                 * Writing past the end of the device.
     160                                 */
     161                                retval = ELIMIT;
     162                                break;
     163                        }
     164                        fibril_rwlock_write_lock(&rd_lock);
     165                        memcpy(rd_addr + offset * block_size, fs_va, block_size);
     166                        fibril_rwlock_write_unlock(&rd_lock);
     167                        retval = EOK;
    151168                        break;
    152                 case BD_GET_BLOCK_SIZE:
    153                         ipc_answer_1(callid, EOK, block_size);
    154                         continue;
    155169                default:
    156170                        /*
     
    167181}
    168182
    169 /** Read blocks from the device. */
    170 static int rd_read_blocks(uint64_t ba, size_t cnt, void *buf)
    171 {
    172         if ((ba + cnt) * block_size > rd_size) {
    173                 /* Reading past the end of the device. */
    174                 return ELIMIT;
    175         }
    176 
    177         fibril_rwlock_read_lock(&rd_lock);
    178         memcpy(buf, rd_addr + ba * block_size, block_size * cnt);
    179         fibril_rwlock_read_unlock(&rd_lock);
    180 
    181         return EOK;
    182 }
    183 
    184 /** Write blocks to the device. */
    185 static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf)
    186 {
    187         if ((ba + cnt) * block_size > rd_size) {
    188                 /* Writing past the end of the device. */
    189                 return ELIMIT;
    190         }
    191 
    192         fibril_rwlock_write_lock(&rd_lock);
    193         memcpy(rd_addr + ba * block_size, buf, block_size * cnt);
    194         fibril_rwlock_write_unlock(&rd_lock);
    195 
    196         return EOK;
    197 }
    198 
    199183/** Prepare the ramdisk image for operation. */
    200184static bool rd_init(void)
  • uspace/srv/fs/fat/fat_ops.c

    r056fa40 rcffce57  
    818818
    819819        /* prepare the boot block */
    820         rc = block_bb_read(dev_handle, BS_BLOCK);
     820        rc = block_bb_read(dev_handle, BS_BLOCK * BS_SIZE, BS_SIZE);
    821821        if (rc != EOK) {
    822822                block_fini(dev_handle);
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    r056fa40 rcffce57  
    4747#include <byteorder.h>
    4848
    49 #define TMPFS_COMM_SIZE         1024
     49#define TMPFS_BLOCK_SIZE        1024
    5050
    5151struct rdentry {
     
    6969               
    7070                if (block_seqread(dev, bufpos, buflen, pos, &entry,
    71                     sizeof(entry)) != EOK)
     71                    sizeof(entry), TMPFS_BLOCK_SIZE) != EOK)
    7272                        return false;
    7373               
     
    8989                       
    9090                        if (block_seqread(dev, bufpos, buflen, pos, fname,
    91                             entry.len) != EOK) {
     91                            entry.len, TMPFS_BLOCK_SIZE) != EOK) {
    9292                                ops->destroy(fn);
    9393                                free(fname);
     
    105105                       
    106106                        if (block_seqread(dev, bufpos, buflen, pos, &size,
    107                             sizeof(size)) != EOK)
     107                            sizeof(size), TMPFS_BLOCK_SIZE) != EOK)
    108108                                return false;
    109109                       
     
    117117                        nodep->size = size;
    118118                        if (block_seqread(dev, bufpos, buflen, pos, nodep->data,
    119                             size) != EOK)
     119                            size, TMPFS_BLOCK_SIZE) != EOK)
    120120                                return false;
    121121                       
     
    133133                       
    134134                        if (block_seqread(dev, bufpos, buflen, pos, fname,
    135                             entry.len) != EOK) {
     135                            entry.len, TMPFS_BLOCK_SIZE) != EOK) {
    136136                                ops->destroy(fn);
    137137                                free(fname);
     
    166166        int rc;
    167167
    168         rc = block_init(dev, TMPFS_COMM_SIZE);
     168        rc = block_init(dev, TMPFS_BLOCK_SIZE);
    169169        if (rc != EOK)
    170170                return false;
     
    175175       
    176176        char tag[6];
    177         if (block_seqread(dev, &bufpos, &buflen, &pos, tag, 5) != EOK)
     177        if (block_seqread(dev, &bufpos, &buflen, &pos, tag, 5,
     178            TMPFS_BLOCK_SIZE) != EOK)
    178179                goto error;
    179180       
Note: See TracChangeset for help on using the changeset viewer.