Changeset 7858bc5f in mainline for uspace/lib/libblock/libblock.c
- Timestamp:
- 2008-10-28T15:40:19Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 916bf1a
- Parents:
- 5cf723b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r5cf723b r7858bc5f 39 39 #include "../../srv/vfs/vfs.h" 40 40 #include "../../srv/rd/rd.h" 41 #include <ipc/devmap.h> 42 #include <ipc/services.h> 41 43 #include <errno.h> 44 #include <sys/mman.h> 42 45 #include <async.h> 43 46 #include <ipc/ipc.h> … … 45 48 #include <assert.h> 46 49 50 static int dev_phone = -1; /* FIXME */ 51 static void *dev_buffer = NULL; /* FIXME */ 52 static size_t dev_buffer_len = 0; /* FIXME */ 53 static void *bblock = NULL; /* FIXME */ 54 55 int 56 block_init(dev_handle_t dev_handle, size_t com_size, off_t bb_off, 57 size_t bb_size) 58 { 59 int rc; 60 61 bblock = malloc(bb_size); 62 if (!bblock) 63 return ENOMEM; 64 dev_buffer_len = com_size; 65 dev_buffer = mmap(NULL, com_size, PROTO_READ | PROTO_WRITE, 66 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 67 if (!dev_buffer) { 68 free(bblock); 69 return ENOMEM; 70 } 71 dev_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 72 DEVMAP_CONNECT_TO_DEVICE, dev_handle); 73 74 if (dev_phone < 0) { 75 free(bblock); 76 munmap(dev_buffer, com_size); 77 return dev_phone; 78 } 79 80 rc = ipc_share_out_start(dev_phone, dev_buffer, 81 AS_AREA_READ | AS_AREA_WRITE); 82 if (rc != EOK) { 83 ipc_hangup(dev_phone); 84 free(bblock); 85 munmap(dev_buffer, com_size); 86 return rc; 87 } 88 off_t bufpos = 0; 89 size_t buflen = 0; 90 if (!block_read(dev_handle, &bufpos, &buflen, &bb_off, 91 bblock, bb_size, bb_size)) { 92 ipc_hangup(dev_phone); 93 free(bblock); 94 munmap(dev_buffer, com_size); 95 return EIO; /* XXX real error code */ 96 } 97 return EOK; 98 } 99 100 void block_fini(dev_handle_t dev_handle) 101 { 102 /* XXX */ 103 free(bblock); 104 munmap(dev_buffer, dev_buffer_len); 105 ipc_hangup(dev_phone); 106 } 107 108 void *block_bb_get(dev_handle_t dev_handle) 109 { 110 /* XXX */ 111 return bblock; 112 } 113 47 114 /** Read data from a block device. 48 115 * 49 * @param phone Phone to be used to communicate with the device. 50 * @param buffer Communication buffer shared with the device. 116 * @param dev_handle Device handle of the block device. 51 117 * @param bufpos Pointer to the first unread valid offset within the 52 118 * communication buffer. … … 60 126 * @return True on success, false on failure. 61 127 */ 62 bool blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen, 63 off_t *pos, void *dst, size_t size, size_t block_size) 128 bool 129 block_read(int dev_handle, off_t *bufpos, size_t *buflen, off_t *pos, void *dst, 130 size_t size, size_t block_size) 64 131 { 65 132 off_t offset = 0; … … 79 146 * destination buffer. 80 147 */ 81 memcpy(dst + offset, buffer + *bufpos, rd);148 memcpy(dst + offset, dev_buffer + *bufpos, rd); 82 149 offset += rd; 83 150 *bufpos += rd; … … 89 156 /* Refill the communication buffer with a new block. */ 90 157 ipcarg_t retval; 91 int rc = async_req_2_1( phone, RD_READ_BLOCK,158 int rc = async_req_2_1(dev_phone, RD_READ_BLOCK, 92 159 *pos / block_size, block_size, &retval); 93 160 if ((rc != EOK) || (retval != EOK)) … … 101 168 return true; 102 169 } 103 104 int dev_phone = -1; /* FIXME */105 void *dev_buffer = NULL; /* FIXME */106 170 107 171 block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs) … … 127 191 b->size = bs; 128 192 129 if (!block read(dev_phone, dev_buffer, &bufpos, &buflen, &pos, b->data,193 if (!block_read(dev_handle, &bufpos, &buflen, &pos, b->data, 130 194 bs, bs)) { 131 195 free(b->data);
Note:
See TracChangeset
for help on using the changeset viewer.