Changeset 0ee4322 in mainline for uspace/srv
- Timestamp:
- 2008-01-13T13:19:37Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d0dc74ae
- Parents:
- 4fb6bf36
- Location:
- uspace/srv
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs.h
r4fb6bf36 r0ee4322 1 1 /* 2 * Copyright (c) 200 7Jakub Jermar2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 64 64 extern void tmpfs_read(ipc_callid_t, ipc_call_t *); 65 65 extern void tmpfs_write(ipc_callid_t, ipc_call_t *); 66 extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *); 66 67 67 68 #endif -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r4fb6bf36 r0ee4322 369 369 return; 370 370 } 371 /* Clear any newly allocated memory in order to emulate gaps. 371 /* Clear any newly allocated memory in order to emulate gaps. */ 372 372 memset(newdata + dentry->size, 0, delta); 373 373 dentry->size += delta; … … 377 377 } 378 378 379 void 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 379 416 /** 380 417 * @} -
uspace/srv/vfs/vfs.c
r4fb6bf36 r0ee4322 1 1 /* 2 * Copyright (c) 200 7Jakub Jermar2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 104 104 break; 105 105 case VFS_TRUNCATE: 106 vfs_truncate(callid, &call); 107 break; 106 108 case VFS_UNMOUNT: 107 109 case VFS_CLOSE: -
uspace/srv/vfs/vfs.h
r4fb6bf36 r0ee4322 230 230 extern void vfs_write(ipc_callid_t, ipc_call_t *); 231 231 extern void vfs_seek(ipc_callid_t, ipc_call_t *); 232 extern void vfs_truncate(ipc_callid_t, ipc_call_t *); 232 233 233 234 #endif -
uspace/srv/vfs/vfs_ops.c
r4fb6bf36 r0ee4322 690 690 } 691 691 692 void 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 692 719 atomic_t fs_head_futex = FUTEX_INITIALIZER; 693 720 link_t fs_head;
Note:
See TracChangeset
for help on using the changeset viewer.