Changeset 0ee4322 in mainline for uspace/srv


Ignore:
Timestamp:
2008-01-13T13:19:37Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d0dc74ae
Parents:
4fb6bf36
Message:

Add ftruncate() and support for VFS_TRUNCATE to VFS and TMPFS.

Location:
uspace/srv
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs.h

    r4fb6bf36 r0ee4322  
    11/*
    2  * Copyright (c) 2007 Jakub Jermar
     2 * Copyright (c) 2008 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    6464extern void tmpfs_read(ipc_callid_t, ipc_call_t *);
    6565extern void tmpfs_write(ipc_callid_t, ipc_call_t *);
     66extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *);
    6667
    6768#endif
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r4fb6bf36 r0ee4322  
    369369                return;
    370370        }
    371         /* Clear any newly allocated memory in order to emulate gaps.  */
     371        /* Clear any newly allocated memory in order to emulate gaps. */
    372372        memset(newdata + dentry->size, 0, delta);
    373373        dentry->size += delta;
     
    377377}
    378378
     379void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
     380{
     381        int dev_handle = IPC_GET_ARG1(*request);
     382        unsigned long index = IPC_GET_ARG2(*request);
     383        size_t size = IPC_GET_ARG3(*request);
     384
     385        /*
     386         * Lookup the respective dentry.
     387         */
     388        link_t *hlp;
     389        hlp = hash_table_find(&dentries, &index);
     390        if (!hlp) {
     391                ipc_answer_0(rid, ENOENT);
     392                return;
     393        }
     394        tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
     395            dh_link);
     396
     397        if (size == dentry->size) {
     398                ipc_answer_0(rid, EOK);
     399                return;
     400        }
     401
     402        void *newdata = realloc(dentry->data, size);
     403        if (!newdata) {
     404                ipc_answer_0(rid, ENOMEM);
     405                return;
     406        }
     407        if (size > dentry->size) {
     408                size_t delta = size - dentry->size;
     409                memset(newdata + dentry->size, 0, delta);
     410        }
     411        dentry->size = size;
     412        dentry->data = newdata;
     413        ipc_answer_0(rid, EOK);
     414}
     415
    379416/**
    380417 * @}
  • uspace/srv/vfs/vfs.c

    r4fb6bf36 r0ee4322  
    11/*
    2  * Copyright (c) 2007 Jakub Jermar
     2 * Copyright (c) 2008 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    104104                        break;
    105105                case VFS_TRUNCATE:
     106                        vfs_truncate(callid, &call);
     107                        break;
    106108                case VFS_UNMOUNT:
    107109                case VFS_CLOSE:
  • uspace/srv/vfs/vfs.h

    r4fb6bf36 r0ee4322  
    230230extern void vfs_write(ipc_callid_t, ipc_call_t *);
    231231extern void vfs_seek(ipc_callid_t, ipc_call_t *);
     232extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
    232233
    233234#endif
  • uspace/srv/vfs/vfs_ops.c

    r4fb6bf36 r0ee4322  
    690690}
    691691
     692void vfs_truncate(ipc_callid_t rid, ipc_call_t *request)
     693{
     694        int fd = IPC_GET_ARG1(*request);
     695        size_t size = IPC_GET_ARG2(*request);
     696        ipcarg_t rc;
     697
     698        vfs_file_t *file = vfs_file_get(fd);
     699        if (!file) {
     700                ipc_answer_0(rid, ENOENT);
     701                return;
     702        }
     703        futex_down(&file->lock);
     704
     705        rwlock_write_lock(&file->node->contents_rwlock);
     706        int fs_phone = vfs_grab_phone(file->node->fs_handle);
     707        rc = async_req_3_0(fs_phone, VFS_TRUNCATE, (ipcarg_t)file->node->dev_handle,
     708            (ipcarg_t)file->node->index, (ipcarg_t)size);
     709        vfs_release_phone(fs_phone);
     710        if (rc == EOK)
     711                file->node->size = size;
     712        rwlock_write_unlock(&file->node->contents_rwlock);
     713
     714        futex_up(&file->lock);
     715
     716        return rc;     
     717}
     718
    692719atomic_t fs_head_futex = FUTEX_INITIALIZER;
    693720link_t fs_head;
Note: See TracChangeset for help on using the changeset viewer.