Rev 3386 | Rev 4581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
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) { |
- | 199 | int rc; |
|
- | 200 | ||
200 | if (!ops->link(cur, nodep, component)) { |
201 | rc = ops->link(cur, nodep, component); |
- | 202 | if (rc != EOK) { |
|
201 | if (lflag & L_CREATE) { |
203 | if (lflag & L_CREATE) { |
202 | (void)ops->destroy( |
204 | (void)ops->destroy( |
203 | nodep); |
205 | nodep); |
204 | } |
206 | } |
205 | ipc_answer_0(rid, ENOSPC); |
207 | ipc_answer_0(rid, rc); |
206 | } else { |
208 | } else { |
207 | ipc_answer_5(rid, EOK, |
209 | ipc_answer_5(rid, EOK, |
208 | fs_handle, dev_handle, |
210 | fs_handle, dev_handle, |
209 | ops->index_get(nodep), |
211 | ops->index_get(nodep), |
210 | ops->size_get(nodep), |
212 | ops->size_get(nodep), |
Line 261... | Line 263... | ||
261 | assert(len); |
263 | assert(len); |
262 | component[len] = '\0'; |
264 | component[len] = '\0'; |
263 | 265 | ||
264 | void *nodep; |
266 | void *nodep; |
265 | if (lflag & L_CREATE) |
267 | if (lflag & L_CREATE) |
266 | nodep = ops->create(lflag); |
268 | nodep = ops->create(dev_handle, lflag); |
267 | else |
269 | else |
268 | nodep = ops->node_get(dev_handle, index); |
270 | nodep = ops->node_get(dev_handle, index); |
269 | if (nodep) { |
271 | if (nodep) { |
- | 272 | int rc; |
|
- | 273 | ||
270 | if (!ops->link(cur, nodep, component)) { |
274 | rc = ops->link(cur, nodep, component); |
- | 275 | if (rc != EOK) { |
|
271 | if (lflag & L_CREATE) |
276 | if (lflag & L_CREATE) |
272 | (void)ops->destroy(nodep); |
277 | (void)ops->destroy(nodep); |
273 | ipc_answer_0(rid, ENOSPC); |
278 | ipc_answer_0(rid, rc); |
274 | } else { |
279 | } else { |
275 | ipc_answer_5(rid, EOK, |
280 | ipc_answer_5(rid, EOK, |
276 | fs_handle, dev_handle, |
281 | fs_handle, dev_handle, |
277 | ops->index_get(nodep), |
282 | ops->index_get(nodep), |
278 | ops->size_get(nodep), |
283 | ops->size_get(nodep), |
Line 329... | Line 334... | ||
329 | ops->node_put(cur); |
334 | ops->node_put(cur); |
330 | if (tmp) |
335 | if (tmp) |
331 | ops->node_put(tmp); |
336 | ops->node_put(tmp); |
332 | } |
337 | } |
333 | 338 | ||
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 | /** @} |
339 | /** @} |
392 | */ |
340 | */ |