Changeset 6284978 in mainline for uspace/lib/libblock/libblock.c
- Timestamp:
- 2008-11-02T10:21:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c243b4
- Parents:
- 2953f9a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r2953f9a r6284978 83 83 84 84 static int devcon_add(dev_handle_t dev_handle, int dev_phone, void *com_area, 85 size_t com_size , void *bb_buf, off_t bb_off, size_t bb_size)85 size_t com_size) 86 86 { 87 87 link_t *cur; … … 97 97 devcon->com_area = com_area; 98 98 devcon->com_size = com_size; 99 devcon->bb_buf = bb_buf;100 devcon->bb_off = bb_off;101 devcon->bb_size = bb_size;99 devcon->bb_buf = NULL; 100 devcon->bb_off = 0; 101 devcon->bb_size = 0; 102 102 103 103 futex_down(&dcl_lock); … … 122 122 } 123 123 124 int 125 block_init(dev_handle_t dev_handle, size_t com_size, off_t bb_off, 126 size_t bb_size) 124 int block_init(dev_handle_t dev_handle, size_t com_size) 127 125 { 128 126 int rc; 129 127 int dev_phone; 130 128 void *com_area; 131 void *bb_buf;132 133 bb_buf = malloc(bb_size);134 if (!bb_buf)135 return ENOMEM;136 129 137 130 com_area = mmap(NULL, com_size, PROTO_READ | PROTO_WRITE, 138 131 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 139 132 if (!com_area) { 140 free(bb_buf);141 133 return ENOMEM; 142 134 } … … 145 137 146 138 if (dev_phone < 0) { 147 free(bb_buf);148 139 munmap(com_area, com_size); 149 140 return dev_phone; … … 153 144 AS_AREA_READ | AS_AREA_WRITE); 154 145 if (rc != EOK) { 155 free(bb_buf);156 146 munmap(com_area, com_size); 157 147 ipc_hangup(dev_phone); … … 159 149 } 160 150 161 rc = devcon_add(dev_handle, dev_phone, com_area, com_size, bb_buf, 162 bb_off, bb_size); 151 rc = devcon_add(dev_handle, dev_phone, com_area, com_size); 163 152 if (rc != EOK) { 164 free(bb_buf);165 153 munmap(com_area, com_size); 166 154 ipc_hangup(dev_phone); … … 168 156 } 169 157 158 return EOK; 159 } 160 161 void block_fini(dev_handle_t dev_handle) 162 { 163 devcon_t *devcon = devcon_search(dev_handle); 164 assert(devcon); 165 166 devcon_remove(devcon); 167 168 if (devcon->bb_buf) 169 free(devcon->bb_buf); 170 munmap(devcon->com_area, devcon->com_size); 171 ipc_hangup(devcon->dev_phone); 172 173 free(devcon); 174 } 175 176 int block_bb_read(dev_handle_t dev_handle, off_t off, size_t size) 177 { 178 void *bb_buf; 179 180 devcon_t *devcon = devcon_search(dev_handle); 181 if (!devcon) 182 return ENOENT; 183 if (devcon->bb_buf) 184 return EEXIST; 185 bb_buf = malloc(size); 186 if (!bb_buf) 187 return ENOMEM; 188 170 189 off_t bufpos = 0; 171 190 size_t buflen = 0; 172 if (!block_read(dev_handle, &bufpos, &buflen, & bb_off,173 bb_buf, bb_size, bb_size)) {174 block_fini(dev_handle);191 if (!block_read(dev_handle, &bufpos, &buflen, &off, 192 bb_buf, size, size)) { 193 free(bb_buf); 175 194 return EIO; /* XXX real error code */ 176 195 } 177 196 devcon->bb_buf = bb_buf; 197 devcon->bb_off = off; 198 devcon->bb_size = size; 199 178 200 return EOK; 179 }180 181 void block_fini(dev_handle_t dev_handle)182 {183 devcon_t *devcon = devcon_search(dev_handle);184 assert(devcon);185 186 devcon_remove(devcon);187 188 free(devcon->bb_buf);189 munmap(devcon->com_area, devcon->com_size);190 ipc_hangup(devcon->dev_phone);191 192 free(devcon);193 201 } 194 202
Note:
See TracChangeset
for help on using the changeset viewer.