Subversion Repositories HelenOS

Rev

Rev 2664 | Rev 2667 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2664 Rev 2666
Line 313... Line 313...
313
     * Answer the VFS_READ call.
313
     * Answer the VFS_READ call.
314
     */
314
     */
315
    ipc_answer_1(rid, EOK, bytes);
315
    ipc_answer_1(rid, EOK, bytes);
316
}
316
}
317
 
317
 
-
 
318
void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
-
 
319
{
-
 
320
    int dev_handle = IPC_GET_ARG1(*request);
-
 
321
    unsigned long index = IPC_GET_ARG2(*request);
-
 
322
    off_t pos = IPC_GET_ARG3(*request);
-
 
323
 
-
 
324
    /*
-
 
325
     * Lookup the respective dentry.
-
 
326
     */
-
 
327
    link_t *hlp;
-
 
328
    hlp = hash_table_find(&dentries, &index);
-
 
329
    if (!hlp) {
-
 
330
        ipc_answer_0(rid, ENOENT);
-
 
331
        return;
-
 
332
    }
-
 
333
    tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
-
 
334
        dh_link);
-
 
335
 
-
 
336
    /*
-
 
337
     * Receive the write request.
-
 
338
     */
-
 
339
    ipc_callid_t callid;
-
 
340
    size_t size;
-
 
341
    if (!ipc_data_write_receive(&callid, NULL, &size)) {
-
 
342
        ipc_answer_0(callid, EINVAL);  
-
 
343
        ipc_answer_0(rid, EINVAL);
-
 
344
        return;
-
 
345
    }
-
 
346
 
-
 
347
    /*
-
 
348
     * 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);
-
 
354
    if (!newdata) {
-
 
355
        ipc_answer_0(callid, ENOMEM);
-
 
356
        ipc_answer_1(rid, EOK, 0);
-
 
357
        return;
-
 
358
    }
-
 
359
    dentry->size = size;
-
 
360
    dentry->data = newdata;
-
 
361
    (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);
-
 
367
}
-
 
368
 
318
/**
369
/**
319
 * @}
370
 * @}
320
 */
371
 */