Rev 2667 | Rev 2676 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2667 | Rev 2673 | ||
---|---|---|---|
Line 297... | Line 297... | ||
297 | 297 | ||
298 | /* |
298 | /* |
299 | * Receive the read request. |
299 | * Receive the read request. |
300 | */ |
300 | */ |
301 | ipc_callid_t callid; |
301 | ipc_callid_t callid; |
302 | size_t size; |
302 | size_t len; |
303 | if (!ipc_data_read_receive(&callid, &size)) { |
303 | if (!ipc_data_read_receive(&callid, &len)) { |
304 | ipc_answer_0(callid, EINVAL); |
304 | ipc_answer_0(callid, EINVAL); |
305 | ipc_answer_0(rid, EINVAL); |
305 | ipc_answer_0(rid, EINVAL); |
306 | return; |
306 | return; |
307 | } |
307 | } |
308 | 308 | ||
309 | size_t bytes = max(0, min(dentry->size - pos, size)); |
309 | size_t bytes = max(0, min(dentry->size - pos, len)); |
310 | (void) ipc_data_read_deliver(callid, dentry->data + pos, bytes); |
310 | (void) ipc_data_read_deliver(callid, dentry->data + pos, bytes); |
311 | 311 | ||
312 | /* |
312 | /* |
313 | * Answer the VFS_READ call. |
313 | * Answer the VFS_READ call. |
314 | */ |
314 | */ |
Line 335... | Line 335... | ||
335 | 335 | ||
336 | /* |
336 | /* |
337 | * Receive the write request. |
337 | * Receive the write request. |
338 | */ |
338 | */ |
339 | ipc_callid_t callid; |
339 | ipc_callid_t callid; |
340 | size_t size; |
340 | size_t len; |
341 | if (!ipc_data_write_receive(&callid, NULL, &size)) { |
341 | if (!ipc_data_write_receive(&callid, NULL, &len)) { |
342 | ipc_answer_0(callid, EINVAL); |
342 | ipc_answer_0(callid, EINVAL); |
343 | ipc_answer_0(rid, EINVAL); |
343 | ipc_answer_0(rid, EINVAL); |
344 | return; |
344 | return; |
345 | } |
345 | } |
346 | 346 | ||
347 | /* |
347 | /* |
348 | * Check whether the file needs to grow. |
348 | * Check whether the file needs to grow. |
349 | */ |
349 | */ |
350 | if (pos + size <= dentry->size) { |
350 | if (pos + len <= dentry->size) { |
351 | /* The file size is not changing. */ |
351 | /* The file size is not changing. */ |
352 | (void) ipc_data_write_deliver(callid, dentry->data + pos, size); |
352 | (void) ipc_data_write_deliver(callid, dentry->data + pos, len); |
353 | ipc_answer_1(rid, EOK, size); |
353 | ipc_answer_1(rid, EOK, len); |
354 | return; |
354 | return; |
355 | } |
355 | } |
356 | size_t delta = (pos + size) - dentry->size; |
356 | size_t delta = (pos + len) - dentry->size; |
357 | /* |
357 | /* |
358 | * At this point, we are deliberately extremely straightforward and |
358 | * At this point, we are deliberately extremely straightforward and |
359 | * simply realloc the contents of the file on every write that grows the |
359 | * simply realloc the contents of the file on every write that grows the |
360 | * file. In the end, the situation might not be as bad as it may look: |
360 | * file. In the end, the situation might not be as bad as it may look: |
361 | * our heap allocator can save us and just grow the block whenever |
361 | * our heap allocator can save us and just grow the block whenever |
Line 367... | Line 367... | ||
367 | ipc_answer_1(rid, EOK, 0); |
367 | ipc_answer_1(rid, EOK, 0); |
368 | return; |
368 | return; |
369 | } |
369 | } |
370 | dentry->size += delta; |
370 | dentry->size += delta; |
371 | dentry->data = newdata; |
371 | dentry->data = newdata; |
372 | (void) ipc_data_write_deliver(callid, dentry->data + pos, size); |
372 | (void) ipc_data_write_deliver(callid, dentry->data + pos, len); |
373 | ipc_answer_1(rid, EOK, size); |
373 | ipc_answer_1(rid, EOK, len); |
374 | } |
374 | } |
375 | 375 | ||
376 | /** |
376 | /** |
377 | * @} |
377 | * @} |
378 | */ |
378 | */ |