Changeset 0ee4322 in mainline
- 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
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs.c
r4fb6bf36 r0ee4322 95 95 96 96 97 int open(const char * name, int oflag, ...)97 int open(const char *path, int oflag, ...) 98 98 { 99 99 int res; … … 113 113 } 114 114 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)); 116 116 if (rc != EOK) { 117 117 async_wait_for(req, NULL); … … 215 215 } 216 216 217 int 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 217 238 /** @} 218 239 */ -
uspace/lib/libc/include/unistd.h
r4fb6bf36 r0ee4322 46 46 #define SEEK_END 2 47 47 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);48 extern ssize_t write(int, const void *, size_t); 49 extern ssize_t read(int, void *, size_t); 50 50 extern off_t lseek(int, off_t, int); 51 extern int ftruncate(int, off_t); 51 52 52 53 extern void _exit(int status); -
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.