Changeset 7fe1f75 in mainline


Ignore:
Timestamp:
2008-02-28T21:30:50Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ee68e4bc
Parents:
2c448fb
Message:

Support for O_TRUNC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_ops.c

    r2c448fb r7fe1f75  
    5252#include <atomic.h>
    5353#include "vfs.h"
     54
     55/* Forward declarations of static functions. */
     56static int vfs_truncate_internal(int, int, unsigned long, size_t);
    5457
    5558/**
     
    350353        }
    351354
    352         /** Path is no longer needed. */
     355        /* Path is no longer needed. */
    353356        free(path);
    354357
     
    358361        else
    359362                rwlock_read_unlock(&namespace_rwlock);
     363
     364        /* Truncate the file if requested and if necessary. */
     365        if (oflag & O_TRUNC) {
     366                futex_down(&node->contents_rwlock);
     367                if (node->size) {
     368                        rc = vfs_truncate_internal(node->fs_handle,
     369                            node->dev_handle, node->index, 0);
     370                        if (rc) {
     371                                futex_up(&node->contents_rwlock);
     372                                vfs_node_put(node);
     373                                ipc_answer_0(rid, rc);
     374                                return;
     375                        }
     376                        node->size = 0;
     377                }
     378                futex_up(&node->contents_rwlock);
     379        }
    360380
    361381        /*
     
    561581}
    562582
     583int vfs_truncate_internal(int fs_handle, int dev_handle, unsigned long index,
     584    size_t size)
     585{
     586        ipcarg_t rc;
     587        int fs_phone;
     588       
     589        fs_phone = vfs_grab_phone(fs_handle);
     590        rc = async_req_3_0(fs_phone, VFS_TRUNCATE, (ipcarg_t)dev_handle,
     591            (ipcarg_t)index, (ipcarg_t)size);
     592        vfs_release_phone(fs_phone);
     593        return (int)rc;
     594}
     595
    563596void vfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    564597{
    565598        int fd = IPC_GET_ARG1(*request);
    566599        size_t size = IPC_GET_ARG2(*request);
    567         ipcarg_t rc;
     600        int rc;
    568601
    569602        vfs_file_t *file = vfs_file_get(fd);
     
    575608
    576609        rwlock_write_lock(&file->node->contents_rwlock);
    577         int fs_phone = vfs_grab_phone(file->node->fs_handle);
    578         rc = async_req_3_0(fs_phone, VFS_TRUNCATE,
    579             (ipcarg_t)file->node->dev_handle, (ipcarg_t)file->node->index,
    580             (ipcarg_t)size);
    581         vfs_release_phone(fs_phone);
     610        rc = vfs_truncate_internal(file->node->fs_handle,
     611            file->node->dev_handle, file->node->index, size);
    582612        if (rc == EOK)
    583613                file->node->size = size;
     
    585615
    586616        futex_up(&file->lock);
    587         ipc_answer_0(rid, rc);
     617        ipc_answer_0(rid, (ipcarg_t)rc);
    588618}
    589619
Note: See TracChangeset for help on using the changeset viewer.