Rev 2666 | Rev 2673 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2666 | Rev 2667 | ||
|---|---|---|---|
| Line 343... | Line 343... | ||
| 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. |
|
| - | 349 | */ |
|
| - | 350 | if (pos + size <= dentry->size) { |
|
| - | 351 | /* The file size is not changing. */ |
|
| - | 352 | (void) ipc_data_write_deliver(callid, dentry->data + pos, size); |
|
| - | 353 | ipc_answer_1(rid, EOK, size); |
|
| - | 354 | return; |
|
| - | 355 | } |
|
| - | 356 | size_t delta = (pos + size) - dentry->size; |
|
| - | 357 | /* |
|
| 348 | * At this point, we are deliberately extremely straightforward and |
358 | * At this point, we are deliberately extremely straightforward and |
| 349 | * simply realloc the contents of the file on every write. In the end, |
359 | * simply realloc the contents of the file on every write that grows the |
| 350 | * the situation might not be as bad as it may look: our heap allocator |
360 | * file. In the end, the situation might not be as bad as it may look: |
| 351 | * can save us and just grow the block whenever possible. |
361 | * our heap allocator can save us and just grow the block whenever |
| - | 362 | * possible. |
|
| 352 | */ |
363 | */ |
| 353 | void *newdata = realloc(dentry->data, size); |
364 | void *newdata = realloc(dentry->data, dentry->size + delta); |
| 354 | if (!newdata) { |
365 | if (!newdata) { |
| 355 | ipc_answer_0(callid, ENOMEM); |
366 | ipc_answer_0(callid, ENOMEM); |
| 356 | ipc_answer_1(rid, EOK, 0); |
367 | ipc_answer_1(rid, EOK, 0); |
| 357 | return; |
368 | return; |
| 358 | } |
369 | } |
| 359 | dentry->size = size; |
370 | dentry->size += delta; |
| 360 | dentry->data = newdata; |
371 | dentry->data = newdata; |
| 361 | (void) ipc_data_write_deliver(callid, dentry->data + pos, size); |
372 | (void) ipc_data_write_deliver(callid, dentry->data + pos, size); |
| 362 | - | ||
| 363 | /* |
- | |
| 364 | * Answer the VFS_WRITE call. |
- | |
| 365 | */ |
- | |
| 366 | ipc_answer_1(rid, EOK, size); |
373 | ipc_answer_1(rid, EOK, size); |
| 367 | } |
374 | } |
| 368 | 375 | ||
| 369 | /** |
376 | /** |
| 370 | * @} |
377 | * @} |