Rev 3343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3343 | Rev 3593 | ||
|---|---|---|---|
| Line 34... | Line 34... | ||
| 34 | * Glue code which is commonod to all FS implementations. |
34 | * Glue code which is commonod to all FS implementations. |
| 35 | */ |
35 | */ |
| 36 | 36 | ||
| 37 | #include "libfs.h" |
37 | #include "libfs.h" |
| 38 | #include "../../srv/vfs/vfs.h" |
38 | #include "../../srv/vfs/vfs.h" |
| 39 | #include "../../srv/rd/rd.h" |
- | |
| 40 | #include <errno.h> |
39 | #include <errno.h> |
| 41 | #include <async.h> |
40 | #include <async.h> |
| 42 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
| 43 | #include <as.h> |
42 | #include <as.h> |
| 44 | #include <assert.h> |
43 | #include <assert.h> |
| Line 190... | Line 189... | ||
| 190 | ipc_answer_0(rid, ENOTDIR); |
189 | ipc_answer_0(rid, ENOTDIR); |
| 191 | goto out; |
190 | goto out; |
| 192 | } |
191 | } |
| 193 | void *nodep; |
192 | void *nodep; |
| 194 | if (lflag & L_CREATE) |
193 | if (lflag & L_CREATE) |
| 195 | nodep = ops->create(lflag); |
194 | nodep = ops->create(dev_handle, lflag); |
| 196 | else |
195 | else |
| 197 | nodep = ops->node_get(dev_handle, |
196 | nodep = ops->node_get(dev_handle, |
| 198 | index); |
197 | index); |
| 199 | if (nodep) { |
198 | if (nodep) { |
| 200 | if (!ops->link(cur, nodep, component)) { |
199 | if (!ops->link(cur, nodep, component)) { |
| Line 261... | Line 260... | ||
| 261 | assert(len); |
260 | assert(len); |
| 262 | component[len] = '\0'; |
261 | component[len] = '\0'; |
| 263 | 262 | ||
| 264 | void *nodep; |
263 | void *nodep; |
| 265 | if (lflag & L_CREATE) |
264 | if (lflag & L_CREATE) |
| 266 | nodep = ops->create(lflag); |
265 | nodep = ops->create(dev_handle, lflag); |
| 267 | else |
266 | else |
| 268 | nodep = ops->node_get(dev_handle, index); |
267 | nodep = ops->node_get(dev_handle, index); |
| 269 | if (nodep) { |
268 | if (nodep) { |
| 270 | if (!ops->link(cur, nodep, component)) { |
269 | if (!ops->link(cur, nodep, component)) { |
| 271 | if (lflag & L_CREATE) |
270 | if (lflag & L_CREATE) |
| Line 329... | Line 328... | ||
| 329 | ops->node_put(cur); |
328 | ops->node_put(cur); |
| 330 | if (tmp) |
329 | if (tmp) |
| 331 | ops->node_put(tmp); |
330 | ops->node_put(tmp); |
| 332 | } |
331 | } |
| 333 | 332 | ||
| 334 | /** Read data from a block device. |
- | |
| 335 | * |
- | |
| 336 | * @param phone Phone to be used to communicate with the device. |
- | |
| 337 | * @param buffer Communication buffer shared with the device. |
- | |
| 338 | * @param bufpos Pointer to the first unread valid offset within the |
- | |
| 339 | * communication buffer. |
- | |
| 340 | * @param buflen Pointer to the number of unread bytes that are ready in |
- | |
| 341 | * the communication buffer. |
- | |
| 342 | * @param pos Device position to be read. |
- | |
| 343 | * @param dst Destination buffer. |
- | |
| 344 | * @param size Size of the destination buffer. |
- | |
| 345 | * @param block_size Block size to be used for the transfer. |
- | |
| 346 | * |
- | |
| 347 | * @return True on success, false on failure. |
- | |
| 348 | */ |
- | |
| 349 | bool libfs_blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen, |
- | |
| 350 | off_t *pos, void *dst, size_t size, size_t block_size) |
- | |
| 351 | { |
- | |
| 352 | off_t offset = 0; |
- | |
| 353 | size_t left = size; |
- | |
| 354 | - | ||
| 355 | while (left > 0) { |
- | |
| 356 | size_t rd; |
- | |
| 357 | - | ||
| 358 | if (*bufpos + left < *buflen) |
- | |
| 359 | rd = left; |
- | |
| 360 | else |
- | |
| 361 | rd = *buflen - *bufpos; |
- | |
| 362 | - | ||
| 363 | if (rd > 0) { |
- | |
| 364 | /* |
- | |
| 365 | * Copy the contents of the communication buffer to the |
- | |
| 366 | * destination buffer. |
- | |
| 367 | */ |
- | |
| 368 | memcpy(dst + offset, buffer + *bufpos, rd); |
- | |
| 369 | offset += rd; |
- | |
| 370 | *bufpos += rd; |
- | |
| 371 | *pos += rd; |
- | |
| 372 | left -= rd; |
- | |
| 373 | } |
- | |
| 374 | - | ||
| 375 | if (*bufpos == *buflen) { |
- | |
| 376 | /* Refill the communication buffer with a new block. */ |
- | |
| 377 | ipcarg_t retval; |
- | |
| 378 | int rc = async_req_2_1(phone, RD_READ_BLOCK, |
- | |
| 379 | *pos / block_size, block_size, &retval); |
- | |
| 380 | if ((rc != EOK) || (retval != EOK)) |
- | |
| 381 | return false; |
- | |
| 382 | - | ||
| 383 | *bufpos = 0; |
- | |
| 384 | *buflen = block_size; |
- | |
| 385 | } |
- | |
| 386 | } |
- | |
| 387 | - | ||
| 388 | return true; |
- | |
| 389 | } |
- | |
| 390 | - | ||
| 391 | /** @} |
333 | /** @} |
| 392 | */ |
334 | */ |