Changeset 0ee4322 in mainline


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
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/vfs.c

    r4fb6bf36 r0ee4322  
    9595
    9696
    97 int open(const char *name, int oflag, ...)
     97int open(const char *path, int oflag, ...)
    9898{
    9999        int res;
     
    113113        }
    114114        req = async_send_2(vfs_phone, VFS_OPEN, oflag, 0, &answer);
    115         rc = ipc_data_write_start(vfs_phone, name, strlen(name));
     115        rc = ipc_data_write_start(vfs_phone, path, strlen(path));
    116116        if (rc != EOK) {
    117117                async_wait_for(req, NULL);
     
    215215}
    216216
     217int ftruncate(int fildes, off_t length)
     218{
     219        int res;
     220        ipcarg_t rc;
     221       
     222        futex_down(&vfs_phone_futex);
     223        async_serialize_start();
     224        if (vfs_phone < 0) {
     225                res = vfs_connect();
     226                if (res < 0) {
     227                        async_serialize_end();
     228                        futex_up(&vfs_phone_futex);
     229                        return res;
     230                }
     231        }
     232        rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length);
     233        async_serialize_end();
     234        futex_up(&vfs_phone_futex);
     235        return (int) rc;
     236}
     237
    217238/** @}
    218239 */
  • uspace/lib/libc/include/unistd.h

    r4fb6bf36 r0ee4322  
    4646#define SEEK_END        2
    4747
    48 extern ssize_t write(int fd, const void * buf, size_t count);
    49 extern ssize_t read(int fd, void * buf, size_t count);
     48extern ssize_t write(int, const void *, size_t);
     49extern ssize_t read(int, void *, size_t);
    5050extern off_t lseek(int, off_t, int);
     51extern int ftruncate(int, off_t);
    5152
    5253extern void _exit(int status);
  • 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.