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