Changeset c1bf5cb in mainline


Ignore:
Timestamp:
2007-12-26T00:50:49Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8d46bf2
Parents:
ee1b8ca
Message:

The previous commit was not entirely sane.
Handle VFS_WRITE correctly when the file doesn't grow.
Handle it correctly also when the file grows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    ree1b8ca rc1bf5cb  
    346346
    347347        /*
     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        /*
    348358         * At this point, we are deliberately extremely straightforward and
    349          * simply realloc the contents of the file on every write. In the end,
    350          * the situation might not be as bad as it may look: our heap allocator
    351          * can save us and just grow the block whenever possible.
    352          */
    353         void *newdata = realloc(dentry->data, size);
     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:
     361         * our heap allocator can save us and just grow the block whenever
     362         * possible.
     363         */
     364        void *newdata = realloc(dentry->data, dentry->size + delta);
    354365        if (!newdata) {
    355366                ipc_answer_0(callid, ENOMEM);
     
    357368                return;
    358369        }
    359         dentry->size = size;
     370        dentry->size += delta;
    360371        dentry->data = newdata;
    361372        (void) ipc_data_write_deliver(callid, dentry->data + pos, size);
    362 
    363         /*
    364          * Answer the VFS_WRITE call.
    365          */
    366373        ipc_answer_1(rid, EOK, size);
    367374}
Note: See TracChangeset for help on using the changeset viewer.