Changes in / [d044447:2f636b6] in mainline
- Files:
-
- 4 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/amd64/Makefile.inc
rd044447 r2f636b6 52 52 $(USPACEDIR)/srv/fs/fat/fat \ 53 53 $(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 56 55 57 56 RD_APPS = \ -
boot/arch/arm32/loader/Makefile
rd044447 r2f636b6 93 93 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ 94 94 $(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 97 96 ifeq ($(MACHINE),testarm) 98 97 RD_SRVS += \ -
boot/arch/ia32/Makefile.inc
rd044447 r2f636b6 52 52 $(USPACEDIR)/srv/fs/fat/fat \ 53 53 $(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 56 55 57 56 RD_APPS = \ -
boot/arch/ia64/loader/Makefile
rd044447 r2f636b6 104 104 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ 105 105 $(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 108 107 109 108 RD_APPS = \ -
boot/arch/mips32/loader/Makefile
rd044447 r2f636b6 106 106 $(USPACEDIR)/srv/fs/fat/fat \ 107 107 $(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 110 109 111 110 RD_APPS = \ -
boot/arch/ppc32/loader/Makefile
rd044447 r2f636b6 94 94 $(USPACEDIR)/srv/fs/tmpfs/tmpfs \ 95 95 $(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 98 97 99 98 RD_APPS = \ -
boot/arch/sparc64/loader/Makefile
rd044447 r2f636b6 104 104 $(USPACEDIR)/srv/fs/devfs/devfs \ 105 105 $(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 108 107 109 108 ifeq ($(MACHINE),generic) -
kernel/arch/arm32/include/elf.h
rd044447 r2f636b6 27 27 */ 28 28 29 /** @addtogroup arm32 29 /** @addtogroup arm32 30 30 * @{ 31 31 */ … … 37 37 #define KERN_arm32_ELF_H_ 38 38 39 #define ELF_MACHINEEM_ARM39 #define ELF_MACHINE EM_ARM 40 40 41 #ifdef __BE__42 #define ELF_DATA_ENCODINGELFDATA2MSB41 #ifdef BIG_ENDIAN 42 #define ELF_DATA_ENCODING ELFDATA2MSB 43 43 #else 44 #define ELF_DATA_ENCODINGELFDATA2LSB44 #define ELF_DATA_ENCODING ELFDATA2LSB 45 45 #endif 46 46 47 #define ELF_CLASS 47 #define ELF_CLASS ELFCLASS32 48 48 49 49 #endif -
kernel/arch/ia64/include/atomic.h
rd044447 r2f636b6 27 27 */ 28 28 29 /** @addtogroup ia64 29 /** @addtogroup ia64 30 30 * @{ 31 31 */ … … 36 36 #define KERN_ia64_ATOMIC_H_ 37 37 38 /** Atomic addition. 39 * 40 * @param val Atomic value. 41 * @param imm Value to add. 42 * 43 * @return Value before addition. 44 */ 45 static 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 38 55 static inline uint64_t test_and_set(atomic_t *val) 39 56 { … … 41 58 42 59 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) 47 63 ); 48 64 … … 60 76 static inline void atomic_inc(atomic_t *val) 61 77 { 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); 69 79 } 70 80 71 81 static inline void atomic_dec(atomic_t *val) 72 82 { 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); 80 84 } 81 85 82 86 static inline long atomic_preinc(atomic_t *val) 83 87 { 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; 93 89 } 94 90 95 91 static inline long atomic_predec(atomic_t *val) 96 92 { 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; 106 94 } 107 95 108 96 static inline long atomic_postinc(atomic_t *val) 109 97 { 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); 119 99 } 120 100 121 101 static inline long atomic_postdec(atomic_t *val) 122 102 { 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); 132 104 } 133 105 -
kernel/arch/mips32/include/mm/tlb.h
rd044447 r2f636b6 59 59 typedef union { 60 60 struct { 61 #ifdef __BE__61 #ifdef BIG_ENDIAN 62 62 unsigned : 2; /* zero */ 63 63 unsigned pfn : 24; /* frame number */ … … 80 80 typedef union { 81 81 struct { 82 #ifdef __BE__82 #ifdef BIG_ENDIAN 83 83 unsigned vpn2 : 19; 84 84 unsigned : 5; … … 95 95 typedef union { 96 96 struct { 97 #ifdef __BE__97 #ifdef BIG_ENDIAN 98 98 unsigned : 7; 99 99 unsigned mask : 12; … … 110 110 typedef union { 111 111 struct { 112 #ifdef __BE__112 #ifdef BIG_ENDIAN 113 113 unsigned p : 1; 114 114 unsigned : 27; -
uspace/Makefile
rd044447 r2f636b6 52 52 srv/vfs \ 53 53 srv/devmap \ 54 srv/part/mbr_part \55 54 app/tetris \ 56 55 app/tester \ -
uspace/lib/libblock/libblock.c
rd044447 r2f636b6 50 50 #include <adt/list.h> 51 51 #include <adt/hash_table.h> 52 #include <macros.h>53 52 #include <mem.h> 54 53 … … 63 62 typedef struct { 64 63 fibril_mutex_t lock; 65 size_t lblock_size; /**< Logical block size. */64 size_t block_size; /**< Block size. */ 66 65 unsigned block_count; /**< Total number of blocks. */ 67 66 unsigned blocks_cached; /**< Number of cached blocks. */ … … 75 74 dev_handle_t dev_handle; 76 75 int dev_phone; 77 fibril_mutex_t com m_area_lock;78 void *com m_area;79 size_t com m_size;76 fibril_mutex_t com_area_lock; 77 void *com_area; 78 size_t com_size; 80 79 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; 83 82 cache_t *cache; 84 83 } devcon_t; 85 84 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); 85 static int read_block(devcon_t *devcon, bn_t boff, size_t block_size); 86 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size); 89 87 90 88 static devcon_t *devcon_search(dev_handle_t dev_handle) … … 104 102 } 105 103 106 static int devcon_add(dev_handle_t dev_handle, int dev_phone, size_t bsize,107 void *comm_area, size_t comm_size)104 static int devcon_add(dev_handle_t dev_handle, int dev_phone, void *com_area, 105 size_t com_size) 108 106 { 109 107 link_t *cur; 110 108 devcon_t *devcon; 111 112 if (comm_size < bsize)113 return EINVAL;114 109 115 110 devcon = malloc(sizeof(devcon_t)); … … 120 115 devcon->dev_handle = dev_handle; 121 116 devcon->dev_phone = dev_phone; 122 fibril_mutex_initialize(&devcon->com m_area_lock);123 devcon->com m_area = comm_area;124 devcon->com m_size = comm_size;117 fibril_mutex_initialize(&devcon->com_area_lock); 118 devcon->com_area = com_area; 119 devcon->com_size = com_size; 125 120 devcon->bb_buf = NULL; 126 devcon->bb_ addr= 0;127 devcon-> pblock_size = bsize;121 devcon->bb_off = 0; 122 devcon->bb_size = 0; 128 123 devcon->cache = NULL; 129 124 … … 149 144 } 150 145 151 int block_init(dev_handle_t dev_handle, size_t com m_size)146 int block_init(dev_handle_t dev_handle, size_t com_size) 152 147 { 153 148 int rc; 154 149 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, 159 153 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 160 if (!com m_area) {154 if (!com_area) { 161 155 return ENOMEM; 162 156 } … … 164 158 dev_phone = devmap_device_connect(dev_handle, IPC_FLAG_BLOCKING); 165 159 if (dev_phone < 0) { 166 munmap(com m_area, comm_size);160 munmap(com_area, com_size); 167 161 return dev_phone; 168 162 } 169 163 170 rc = ipc_share_out_start(dev_phone, com m_area,164 rc = ipc_share_out_start(dev_phone, com_area, 171 165 AS_AREA_READ | AS_AREA_WRITE); 172 166 if (rc != EOK) { 173 munmap(com m_area, comm_size);167 munmap(com_area, com_size); 174 168 ipc_hangup(dev_phone); 175 169 return rc; 176 170 } 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); 185 173 if (rc != EOK) { 186 munmap(com m_area, comm_size);174 munmap(com_area, com_size); 187 175 ipc_hangup(dev_phone); 188 176 return rc; … … 207 195 } 208 196 209 munmap(devcon->com m_area, devcon->comm_size);197 munmap(devcon->com_area, devcon->com_size); 210 198 ipc_hangup(devcon->dev_phone); 211 199 … … 213 201 } 214 202 215 int block_bb_read(dev_handle_t dev_handle, bn_t ba)203 int block_bb_read(dev_handle_t dev_handle, off_t off, size_t size) 216 204 { 217 205 void *bb_buf; … … 223 211 if (devcon->bb_buf) 224 212 return EEXIST; 225 bb_buf = malloc( devcon->pblock_size);213 bb_buf = malloc(size); 226 214 if (!bb_buf) 227 215 return ENOMEM; 228 229 fibril_mutex_lock(&devcon->com m_area_lock);230 rc = read_block s(devcon, 0, 1);216 217 fibril_mutex_lock(&devcon->com_area_lock); 218 rc = read_block(devcon, 0, size); 231 219 if (rc != EOK) { 232 fibril_mutex_unlock(&devcon->com m_area_lock);220 fibril_mutex_unlock(&devcon->com_area_lock); 233 221 free(bb_buf); 234 222 return rc; 235 223 } 236 memcpy(bb_buf, devcon->com m_area, devcon->pblock_size);237 fibril_mutex_unlock(&devcon->com m_area_lock);224 memcpy(bb_buf, devcon->com_area, size); 225 fibril_mutex_unlock(&devcon->com_area_lock); 238 226 239 227 devcon->bb_buf = bb_buf; 240 devcon->bb_addr = ba; 228 devcon->bb_off = off; 229 devcon->bb_size = size; 241 230 242 231 return EOK; … … 286 275 fibril_mutex_initialize(&cache->lock); 287 276 list_initialize(&cache->free_head); 288 cache-> lblock_size = size;277 cache->block_size = size; 289 278 cache->block_count = blocks; 290 279 cache->blocks_cached = 0; 291 280 cache->mode = mode; 292 293 /* No block size translation a.t.m. */294 assert(cache->lblock_size == devcon->pblock_size);295 281 296 282 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, … … 385 371 if (!b) 386 372 goto recycle; 387 b->data = malloc(cache-> lblock_size);373 b->data = malloc(cache->block_size); 388 374 if (!b->data) { 389 375 free(b); … … 419 405 list_append(&b->free_link, &cache->free_head); 420 406 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); 425 412 if (rc != EOK) { 426 413 /* … … 457 444 block_initialize(b); 458 445 b->dev_handle = dev_handle; 459 b->size = cache-> lblock_size;446 b->size = cache->block_size; 460 447 b->boff = boff; 461 448 hash_table_insert(&cache->block_hash, &key, &b->hash_link); … … 474 461 * the new contents from the device. 475 462 */ 476 fibril_mutex_lock(&devcon->com m_area_lock);477 rc = read_block s(devcon, b->boff, 1);478 memcpy(b->data, devcon->com m_area, cache->lblock_size);479 fibril_mutex_unlock(&devcon->com m_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); 480 467 if (rc != EOK) 481 468 b->toxic = true; … … 534 521 if (block->dirty && (block->refcnt == 1) && 535 522 (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) { 536 fibril_mutex_lock(&devcon->com m_area_lock);537 memcpy(devcon->com m_area, block->data, block->size);538 rc = write_block s(devcon, block->boff, 1);539 fibril_mutex_unlock(&devcon->com m_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); 540 527 block->dirty = false; 541 528 } … … 614 601 */ 615 602 int 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) 617 604 { 618 605 off_t offset = 0; 619 606 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); 624 608 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); 628 611 while (left > 0) { 629 612 size_t rd; … … 639 622 * destination buffer. 640 623 */ 641 memcpy(dst + offset, devcon->com m_area + *bufpos, rd);624 memcpy(dst + offset, devcon->com_area + *bufpos, rd); 642 625 offset += rd; 643 626 *bufpos += rd; … … 650 633 int rc; 651 634 652 rc = read_block s(devcon, *pos / block_size, 1);635 rc = read_block(devcon, *pos / block_size, block_size); 653 636 if (rc != EOK) { 654 fibril_mutex_unlock(&devcon->com m_area_lock);637 fibril_mutex_unlock(&devcon->com_area_lock); 655 638 return rc; 656 639 } … … 660 643 } 661 644 } 662 fibril_mutex_unlock(&devcon->com m_area_lock);645 fibril_mutex_unlock(&devcon->com_area_lock); 663 646 664 647 return EOK; 665 648 } 666 649 667 /** Read block s directly from device (bypass cache).668 * 669 * @param dev _handle Device handle of the block device.670 * @param b a 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. 672 655 * @param src Buffer for storing the data. 673 656 * 674 657 * @return EOK on success or negative error code on failure. 675 658 */ 676 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)677 { 678 devcon_t *devcon;659 static int read_block(devcon_t *devcon, bn_t boff, size_t block_size) 660 { 661 ipcarg_t retval; 679 662 int rc; 680 663 681 devcon = devcon_search(dev_handle);682 664 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. 701 679 * 702 680 * @return EOK on success or negative error code on failure. 703 681 */ 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; 682 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size) 683 { 684 ipcarg_t retval; 708 685 int rc; 709 686 710 devcon = devcon_search(dev_handle);711 687 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; 789 694 } 790 695 -
uspace/lib/libblock/libblock.h
rd044447 r2f636b6 60 60 #define BLOCK_FLAGS_NOREAD 1 61 61 62 typedef u int64_tbn_t; /**< Block number type. */62 typedef unsigned bn_t; /**< Block number type. */ 63 63 64 64 typedef struct block { … … 98 98 extern void block_fini(dev_handle_t); 99 99 100 extern int block_bb_read(dev_handle_t, bn_t);100 extern int block_bb_read(dev_handle_t, off_t, size_t); 101 101 extern void *block_bb_get(dev_handle_t); 102 102 … … 107 107 108 108 extern 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); 114 110 115 111 #endif -
uspace/lib/libc/arch/ia64/include/atomic.h
rd044447 r2f636b6 27 27 */ 28 28 29 /** @addtogroup libcia64 29 /** @addtogroup libcia64 30 30 * @{ 31 31 */ … … 36 36 #define LIBC_ia64_ATOMIC_H_ 37 37 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 */ 45 static inline long atomic_add(atomic_t *val, int imm) 39 46 { 40 47 long v; 41 42 asm volatile (43 "fetchadd8.rel %[v] = %[count], 1\n"44 : [v] "=r" (v),45 [count] "+m" (val->count)46 );47 }48 48 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 96 51 return v; 97 52 } 98 53 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 } 54 static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); } 55 static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); } 56 57 static inline long atomic_preinc(atomic_t *val) { return atomic_add(val, 1) + 1; } 58 static inline long atomic_predec(atomic_t *val) { return atomic_add(val, -1) - 1; } 59 60 static inline long atomic_postinc(atomic_t *val) { return atomic_add(val, 1); } 61 static inline long atomic_postdec(atomic_t *val) { return atomic_add(val, -1); } 111 62 112 63 #endif -
uspace/lib/libc/include/ipc/bd.h
rd044447 r2f636b6 39 39 40 40 typedef 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 44 43 } bd_request_t; 45 44 -
uspace/srv/bd/ata_bd/ata_bd.c
rd044447 r2f636b6 62 62 #include <bool.h> 63 63 #include <task.h> 64 #include <macros.h>65 64 66 65 #include "ata_bd.h" … … 87 86 static int ata_bd_init(void); 88 87 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall); 89 static int ata_bd_r ead_blocks(int disk_id, uint64_t ba, size_t cnt,88 static int ata_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size, 90 89 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, 90 static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 94 91 void *buf); 95 static int ata_bd_write_block(int disk_id, uint64_t b a, size_tcnt,92 static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 96 93 const void *buf); 97 94 static int disk_init(disk_t *d, int disk_id); 98 95 static int drive_identify(int drive_id, void *buf); 99 96 static void disk_print_summary(disk_t *d); 100 static int coord_calc(disk_t *d, uint64_t b a, block_coord_t *bc);97 static int coord_calc(disk_t *d, uint64_t blk_idx, block_coord_t *bc); 101 98 static void coord_sc_program(const block_coord_t *bc, uint16_t scnt); 102 99 static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus, … … 231 228 int flags; 232 229 int retval; 233 uint64_t ba;234 size_t cnt;230 off_t idx; 231 size_t size; 235 232 int disk_id, i; 236 233 … … 273 270 ipc_answer_0(callid, EOK); 274 271 return; 275 case BD_READ_BLOCK S: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 = E LIMIT;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; 281 278 break; 282 279 } 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); 284 282 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;298 283 default: 299 284 retval = EINVAL; … … 388 373 } 389 374 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 */ 385 static int ata_bd_rdwr(int disk_id, ipcarg_t method, off_t blk_idx, size_t size, 386 void *buf) 387 { 394 388 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 398 401 if (rc != EOK) 399 402 return rc; 400 403 401 ++ba;402 --cnt;403 404 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; 423 411 } 424 412 … … 478 466 * 479 467 * @param disk_id Device index (0 or 1) 480 * @param b a Addressthe first block.481 * @param cntNumber of blocks to transfer.468 * @param blk_idx Index of the first block. 469 * @param blk_cnt Number of blocks to transfer. 482 470 * @param buf Buffer for holding the data. 483 471 * 484 472 * @return EOK on success, EIO on error. 485 473 */ 486 static int ata_bd_read_block(int disk_id, uint64_t b a, size_t blk_cnt,474 static int ata_bd_read_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 487 475 void *buf) 488 476 { … … 498 486 499 487 /* Compute block coordinates. */ 500 if (coord_calc(d, b a, &bc) != EOK)488 if (coord_calc(d, blk_idx, &bc) != EOK) 501 489 return EINVAL; 502 490 … … 553 541 * 554 542 * @param disk_id Device index (0 or 1) 555 * @param b a Addressof the first block.556 * @param cntNumber of blocks to transfer.543 * @param blk_idx Index of the first block. 544 * @param blk_cnt Number of blocks to transfer. 557 545 * @param buf Buffer holding the data to write. 558 546 * 559 547 * @return EOK on success, EIO on error. 560 548 */ 561 static int ata_bd_write_block(int disk_id, uint64_t b a, size_tcnt,549 static int ata_bd_write_block(int disk_id, uint64_t blk_idx, size_t blk_cnt, 562 550 const void *buf) 563 551 { … … 572 560 573 561 /* Compute block coordinates. */ 574 if (coord_calc(d, b a, &bc) != EOK)562 if (coord_calc(d, blk_idx, &bc) != EOK) 575 563 return EINVAL; 576 564 … … 632 620 * @return EOK on success or EINVAL if block index is past end of device. 633 621 */ 634 static int coord_calc(disk_t *d, uint64_t b a, block_coord_t *bc)622 static int coord_calc(disk_t *d, uint64_t blk_idx, block_coord_t *bc) 635 623 { 636 624 uint64_t c; … … 638 626 639 627 /* Check device bounds. */ 640 if (b a>= d->blocks)628 if (blk_idx >= d->blocks) 641 629 return EINVAL; 642 630 … … 646 634 case am_chs: 647 635 /* Compute CHS coordinates. */ 648 c = b a/ (d->geom.heads * d->geom.sectors);649 idx = b a% (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); 650 638 651 639 bc->cyl_lo = c & 0xff; … … 657 645 case am_lba28: 658 646 /* Compute LBA-28 coordinates. */ 659 bc->c0 = b a& 0xff; /* bits 0-7 */660 bc->c1 = (b a >> 8) & 0xff;/* bits 8-15 */661 bc->c2 = (b a>> 16) & 0xff; /* bits 16-23 */662 bc->h = (b a>> 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 */ 663 651 break; 664 652 665 653 case am_lba48: 666 654 /* Compute LBA-48 coordinates. */ 667 bc->c0 = b a& 0xff; /* bits 0-7 */668 bc->c1 = (b a >> 8) & 0xff;/* bits 8-15 */669 bc->c2 = (b a>> 16) & 0xff; /* bits 16-23 */670 bc->c3 = (b a>> 24) & 0xff; /* bits 24-31 */671 bc->c4 = (b a>> 32) & 0xff; /* bits 32-39 */672 bc->c5 = (b a>> 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 */ 673 661 bc->h = 0; 674 662 break; -
uspace/srv/bd/file_bd/file_bd.c
rd044447 r2f636b6 51 51 #include <bool.h> 52 52 #include <task.h> 53 #include <macros.h>54 53 55 54 #define NAME "file_bd" 56 55 57 static const size_t block_size = 512;56 static size_t comm_size; 58 57 static FILE *img; 59 58 … … 63 62 static int file_bd_init(const char *fname); 64 63 static 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, constvoid *buf);64 static int file_bd_read(off_t blk_idx, size_t size, void *buf); 65 static int file_bd_write(off_t blk_idx, size_t size, void *buf); 67 66 68 67 int main(int argc, char **argv) … … 121 120 ipc_call_t call; 122 121 ipcarg_t method; 123 size_t comm_size;124 122 int flags; 125 123 int retval; 126 uint64_t ba;127 size_t cnt;124 off_t idx; 125 size_t size; 128 126 129 127 /* Answer the IPC_M_CONNECT_ME_TO call. */ … … 151 149 ipc_answer_0(callid, EOK); 152 150 return; 153 case BD_READ_BLOCK S: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 = E LIMIT;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; 159 157 break; 160 158 } 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); 162 163 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;176 164 default: 177 165 retval = EINVAL; … … 182 170 } 183 171 184 /** Read blocks from the device. */ 185 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf) 172 static int file_bd_read(off_t blk_idx, size_t size, void *buf) 186 173 { 187 174 size_t n_rd; … … 189 176 fibril_mutex_lock(&dev_lock); 190 177 191 fseek(img, b a * 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); 193 180 194 181 if (ferror(img)) { … … 199 186 fibril_mutex_unlock(&dev_lock); 200 187 201 if (n_rd < cnt)202 return EINVAL; /* Read beyond end of d evice*/188 if (n_rd < size) 189 return EINVAL; /* Read beyond end of disk */ 203 190 204 191 return EOK; 205 192 } 206 193 207 /** Write blocks to the device. */ 208 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf) 194 static int file_bd_write(off_t blk_idx, size_t size, void *buf) 209 195 { 210 196 size_t n_wr; … … 212 198 fibril_mutex_lock(&dev_lock); 213 199 214 fseek(img, b a * 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) { 218 204 fibril_mutex_unlock(&dev_lock); 219 205 return EIO; /* Write error */ -
uspace/srv/bd/gxe_bd/gxe_bd.c
rd044447 r2f636b6 47 47 #include <sys/types.h> 48 48 #include <errno.h> 49 #include <macros.h>50 49 #include <task.h> 51 50 … … 98 97 static int gxe_bd_init(void); 99 98 static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall); 100 static int gx e_bd_read_blocks(int disk_id, uint64_t ba, unsigned cnt,99 static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size, 101 100 void *buf); 102 static int gxe_bd_write_blocks(int disk_id, uint64_t ba, unsigned cnt, 101 static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size, 102 void *buf); 103 static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size, 103 104 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);106 105 107 106 int main(int argc, char **argv) … … 164 163 int flags; 165 164 int retval; 166 uint64_t ba;167 unsigned cnt;165 off_t idx; 166 size_t size; 168 167 int disk_id, i; 169 168 … … 186 185 187 186 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) {193 187 ipc_answer_0(callid, EHANGUP); 194 188 return; … … 211 205 ipc_answer_0(callid, EOK); 212 206 return; 213 case BD_READ_BLOCK S: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 = E LIMIT;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; 219 213 break; 220 214 } 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); 222 217 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;236 218 default: 237 219 retval = EINVAL; … … 242 224 } 243 225 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 226 static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size, 227 void *buf) 228 { 248 229 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 252 240 if (rc != EOK) 253 241 return rc; 254 242 255 ++ba;256 --cnt;257 243 buf += block_size; 244 offset += block_size; 245 246 if (size > block_size) 247 size -= block_size; 248 else 249 size = 0; 258 250 } 259 251 … … 261 253 } 262 254 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) 255 static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size, 256 void *buf) 284 257 { 285 258 uint32_t status; 286 uint64_t byte_addr;287 259 size_t i; 288 260 uint32_t w; 289 261 290 byte_addr = ba * block_size;291 292 262 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); 295 265 pio_write_32(&dev->disk_id, disk_id); 296 266 pio_write_32(&dev->control, CTL_READ_START); … … 302 272 } 303 273 304 for (i = 0; i < block_size; i++) {274 for (i = 0; i < size; i++) { 305 275 ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]); 306 276 } … … 310 280 } 311 281 312 /** Write a block to the device. */ 313 static int gxe_bd_write_block(int disk_id, uint64_t ba,const void *buf)282 static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size, 283 const void *buf) 314 284 { 315 285 uint32_t status; 316 uint64_t byte_addr;317 286 size_t i; 318 287 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 } 320 291 321 292 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); 329 295 pio_write_32(&dev->disk_id, disk_id); 330 296 pio_write_32(&dev->control, CTL_WRITE_START); -
uspace/srv/bd/rd/rd.c
rd044447 r2f636b6 55 55 #include <devmap.h> 56 56 #include <ipc/bd.h> 57 #include <macros.h>58 57 59 58 #define NAME "rd" 60 59 61 /** Pointer to the ramdisk's image */60 /** Pointer to the ramdisk's image. */ 62 61 static void *rd_addr; 63 /** Size of the ramdisk */62 /** Size of the ramdisk. */ 64 63 static 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);71 64 72 65 /** … … 89 82 int retval; 90 83 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; 94 87 95 88 /* … … 102 95 */ 103 96 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); 106 99 if (fs_va) { 107 100 (void) ipc_share_out_finalize(callid, fs_va); … … 130 123 ipc_answer_0(callid, EOK); 131 124 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; 141 146 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; 151 168 break; 152 case BD_GET_BLOCK_SIZE:153 ipc_answer_1(callid, EOK, block_size);154 continue;155 169 default: 156 170 /* … … 167 181 } 168 182 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 199 183 /** Prepare the ramdisk image for operation. */ 200 184 static bool rd_init(void) -
uspace/srv/fs/fat/fat_ops.c
rd044447 r2f636b6 833 833 834 834 /* prepare the boot block */ 835 rc = block_bb_read(dev_handle, BS_BLOCK );835 rc = block_bb_read(dev_handle, BS_BLOCK * BS_SIZE, BS_SIZE); 836 836 if (rc != EOK) { 837 837 block_fini(dev_handle); -
uspace/srv/fs/tmpfs/tmpfs_dump.c
rd044447 r2f636b6 47 47 #include <byteorder.h> 48 48 49 #define TMPFS_ COMM_SIZE102449 #define TMPFS_BLOCK_SIZE 1024 50 50 51 51 struct rdentry { … … 69 69 70 70 if (block_seqread(dev, bufpos, buflen, pos, &entry, 71 sizeof(entry) ) != EOK)71 sizeof(entry), TMPFS_BLOCK_SIZE) != EOK) 72 72 return false; 73 73 … … 89 89 90 90 if (block_seqread(dev, bufpos, buflen, pos, fname, 91 entry.len ) != EOK) {91 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 92 92 ops->destroy(fn); 93 93 free(fname); … … 105 105 106 106 if (block_seqread(dev, bufpos, buflen, pos, &size, 107 sizeof(size) ) != EOK)107 sizeof(size), TMPFS_BLOCK_SIZE) != EOK) 108 108 return false; 109 109 … … 117 117 nodep->size = size; 118 118 if (block_seqread(dev, bufpos, buflen, pos, nodep->data, 119 size ) != EOK)119 size, TMPFS_BLOCK_SIZE) != EOK) 120 120 return false; 121 121 … … 133 133 134 134 if (block_seqread(dev, bufpos, buflen, pos, fname, 135 entry.len ) != EOK) {135 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 136 136 ops->destroy(fn); 137 137 free(fname); … … 166 166 int rc; 167 167 168 rc = block_init(dev, TMPFS_ COMM_SIZE);168 rc = block_init(dev, TMPFS_BLOCK_SIZE); 169 169 if (rc != EOK) 170 170 return false; … … 175 175 176 176 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) 178 179 goto error; 179 180
Note:
See TracChangeset
for help on using the changeset viewer.