Changeset 852b801 in mainline
- Timestamp:
- 2009-06-28T18:59:02Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 75160a6
- Parents:
- 4198f9c3
- Location:
- uspace
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs/vfs.c
r4198f9c3 r852b801 39 39 #include <dirent.h> 40 40 #include <fcntl.h> 41 #include <stdio.h> 41 42 #include <sys/stat.h> 42 #include <stdio.h>43 43 #include <sys/types.h> 44 44 #include <ipc/ipc.h> … … 315 315 } 316 316 317 int fd_phone(int fildes)318 {319 futex_down(&vfs_phone_futex);320 async_serialize_start();321 vfs_connect();322 323 ipcarg_t device;324 ipcarg_t rc = async_req_1_1(vfs_phone, VFS_IN_DEVICE, fildes, &device);325 326 async_serialize_end();327 futex_up(&vfs_phone_futex);328 329 if (rc != EOK)330 return -1;331 332 return devmap_device_connect((dev_handle_t) device, 0);333 }334 335 int fd_node(int fildes, fdi_node_t *node)336 {337 futex_down(&vfs_phone_futex);338 async_serialize_start();339 vfs_connect();340 341 ipcarg_t fs_handle;342 ipcarg_t dev_handle;343 ipcarg_t index;344 ipcarg_t rc = async_req_1_3(vfs_phone, VFS_IN_NODE, fildes, &fs_handle,345 &dev_handle, &index);346 347 async_serialize_end();348 futex_up(&vfs_phone_futex);349 350 if (rc == EOK) {351 node->fs_handle = (fs_handle_t) fs_handle;352 node->dev_handle = (dev_handle_t) dev_handle;353 node->index = (fs_index_t) index;354 }355 356 return rc;357 }358 359 317 int fsync(int fildes) 360 318 { … … 404 362 futex_up(&vfs_phone_futex); 405 363 return (int) rc; 364 } 365 366 int fstat(int fildes, struct stat *stat) 367 { 368 ipcarg_t rc; 369 ipc_call_t answer; 370 aid_t req; 371 372 futex_down(&vfs_phone_futex); 373 async_serialize_start(); 374 vfs_connect(); 375 376 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 377 rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat)); 378 if (rc != EOK) { 379 async_wait_for(req, NULL); 380 async_serialize_end(); 381 futex_up(&vfs_phone_futex); 382 return (ssize_t) rc; 383 } 384 async_wait_for(req, &rc); 385 async_serialize_end(); 386 futex_up(&vfs_phone_futex); 387 388 return rc; 406 389 } 407 390 … … 599 582 } 600 583 584 int fd_phone(int fildes) 585 { 586 struct stat stat; 587 int rc; 588 589 rc = fstat(fildes, &stat); 590 591 if (!stat.devfs_stat.device) 592 return -1; 593 594 return devmap_device_connect(stat.devfs_stat.device, 0); 595 } 596 597 int fd_node(int fildes, fdi_node_t *node) 598 { 599 struct stat stat; 600 int rc; 601 602 rc = fstat(fildes, &stat); 603 604 if (rc == EOK) { 605 node->fs_handle = stat.fs_handle; 606 node->dev_handle = stat.dev_handle; 607 node->index = stat.index; 608 } 609 610 return rc; 611 } 612 601 613 /** @} 602 614 */ -
uspace/lib/libc/include/ipc/vfs.h
r4198f9c3 r852b801 64 64 VFS_IN_SEEK, 65 65 VFS_IN_TRUNCATE, 66 VFS_IN_FSTAT, 66 67 VFS_IN_CLOSE, 67 68 VFS_IN_MOUNT, … … 73 74 VFS_IN_UNLINK, 74 75 VFS_IN_RENAME, 76 VFS_IN_STAT, 75 77 VFS_IN_NODE 76 78 } vfs_in_request_t; … … 87 89 VFS_OUT_DEVICE, 88 90 VFS_OUT_SYNC, 91 VFS_OUT_STAT, 89 92 VFS_OUT_LOOKUP, 90 93 VFS_OUT_DESTROY, -
uspace/lib/libc/include/sys/stat.h
r4198f9c3 r852b801 37 37 38 38 #include <sys/types.h> 39 #include <bool.h> 40 #include <ipc/vfs.h> 41 #include <ipc/devmap.h> 39 42 43 struct stat { 44 fs_handle_t fs_handle; 45 dev_handle_t dev_handle; 46 fs_index_t index; 47 unsigned lnkcnt; 48 bool is_file; 49 off_t size; 50 union { 51 struct { 52 dev_handle_t device; 53 } devfs_stat; 54 }; 55 }; 56 57 extern int fstat(int, struct stat *); 40 58 extern int mkdir(const char *, mode_t); 41 59 -
uspace/srv/fs/devfs/devfs.c
r4198f9c3 r852b801 80 80 devfs_open_node(callid, &call); 81 81 break; 82 case VFS_OUT_ DEVICE:83 devfs_ device(callid, &call);82 case VFS_OUT_STAT: 83 devfs_stat(callid, &call); 84 84 break; 85 85 case VFS_OUT_READ: -
uspace/srv/fs/devfs/devfs_ops.c
r4198f9c3 r852b801 44 44 #include <fibril_sync.h> 45 45 #include <adt/hash_table.h> 46 #include <sys/stat.h> 46 47 #include "devfs.h" 47 48 #include "devfs_ops.h" … … 278 279 } 279 280 280 void devfs_device(ipc_callid_t rid, ipc_call_t *request) 281 { 281 void devfs_stat(ipc_callid_t rid, ipc_call_t *request) 282 { 283 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 282 284 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 285 286 ipc_callid_t callid; 287 size_t size; 288 if (!ipc_data_read_receive(&callid, &size) || 289 size < sizeof(struct stat)) { 290 ipc_answer_0(callid, EINVAL); 291 ipc_answer_0(rid, EINVAL); 292 return; 293 } 294 295 struct stat *stat = malloc(sizeof(struct stat)); 296 if (!stat) { 297 ipc_answer_0(callid, ENOMEM); 298 ipc_answer_0(rid, ENOMEM); 299 return; 300 } 301 memset(stat, 0, sizeof(struct stat)); 302 303 stat->fs_handle = devfs_reg.fs_handle; 304 stat->dev_handle = dev_handle; 305 stat->index = index; 306 stat->lnkcnt = 1; 307 stat->is_file = (index != 0); 308 stat->size = 0; 283 309 284 310 if (index != 0) { … … 289 315 fibril_mutex_lock(&devices_mutex); 290 316 link_t *lnk = hash_table_find(&devices, key); 291 if (lnk == NULL) { 292 fibril_mutex_unlock(&devices_mutex); 293 ipc_answer_0(rid, ENOENT); 294 return; 295 } 317 if (lnk != NULL) 318 stat->devfs_stat.device = (dev_handle_t)index; 296 319 fibril_mutex_unlock(&devices_mutex); 297 298 ipc_answer_1(rid, EOK, (ipcarg_t) index); 299 } else 300 ipc_answer_0(rid, ENOTSUP); 320 } 321 322 ipc_data_read_finalize(callid, stat, sizeof(struct stat)); 323 ipc_answer_0(rid, EOK); 324 325 free(stat); 301 326 } 302 327 -
uspace/srv/fs/devfs/devfs_ops.h
r4198f9c3 r852b801 43 43 extern void devfs_lookup(ipc_callid_t, ipc_call_t *); 44 44 extern void devfs_open_node(ipc_callid_t, ipc_call_t *); 45 extern void devfs_ device(ipc_callid_t, ipc_call_t *);45 extern void devfs_stat(ipc_callid_t, ipc_call_t *); 46 46 extern void devfs_sync(ipc_callid_t, ipc_call_t *); 47 47 extern void devfs_read(ipc_callid_t, ipc_call_t *); -
uspace/srv/fs/fat/fat.c
r4198f9c3 r852b801 110 110 fat_truncate(callid, &call); 111 111 break; 112 case VFS_OUT_STAT: 113 fat_stat(callid, &call); 114 break; 112 115 case VFS_OUT_CLOSE: 113 116 fat_close(callid, &call); … … 118 121 case VFS_OUT_OPEN_NODE: 119 122 fat_open_node(callid, &call); 120 break;121 case VFS_OUT_DEVICE:122 fat_device(callid, &call);123 123 break; 124 124 case VFS_OUT_SYNC: -
uspace/srv/fs/fat/fat.h
r4198f9c3 r852b801 208 208 extern void fat_write(ipc_callid_t, ipc_call_t *); 209 209 extern void fat_truncate(ipc_callid_t, ipc_call_t *); 210 extern void fat_stat(ipc_callid_t, ipc_call_t *); 210 211 extern void fat_close(ipc_callid_t, ipc_call_t *); 211 212 extern void fat_destroy(ipc_callid_t, ipc_call_t *); 212 213 extern void fat_open_node(ipc_callid_t, ipc_call_t *); 213 extern void fat_ device(ipc_callid_t, ipc_call_t *);214 extern void fat_stat(ipc_callid_t, ipc_call_t *); 214 215 extern void fat_sync(ipc_callid_t, ipc_call_t *); 215 216 -
uspace/srv/fs/fat/fat_ops.c
r4198f9c3 r852b801 1203 1203 } 1204 1204 1205 void fat_ device(ipc_callid_t rid, ipc_call_t *request)1205 void fat_stat(ipc_callid_t rid, ipc_call_t *request) 1206 1206 { 1207 1207 ipc_answer_0(rid, ENOTSUP); -
uspace/srv/fs/tmpfs/tmpfs.c
r4198f9c3 r852b801 126 126 tmpfs_open_node(callid, &call); 127 127 break; 128 case VFS_OUT_ DEVICE:129 tmpfs_ device(callid, &call);128 case VFS_OUT_STAT: 129 tmpfs_stat(callid, &call); 130 130 break; 131 131 case VFS_OUT_SYNC: -
uspace/srv/fs/tmpfs/tmpfs.h
r4198f9c3 r852b801 87 87 extern void tmpfs_write(ipc_callid_t, ipc_call_t *); 88 88 extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *); 89 extern void tmpfs_stat(ipc_callid_t, ipc_call_t *); 89 90 extern void tmpfs_close(ipc_callid_t, ipc_call_t *); 90 91 extern void tmpfs_destroy(ipc_callid_t, ipc_call_t *); 91 92 extern void tmpfs_open_node(ipc_callid_t, ipc_call_t *); 92 extern void tmpfs_device(ipc_callid_t, ipc_call_t *);93 93 extern void tmpfs_sync(ipc_callid_t, ipc_call_t *); 94 94 -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r4198f9c3 r852b801 629 629 } 630 630 631 void tmpfs_ device(ipc_callid_t rid, ipc_call_t *request)631 void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request) 632 632 { 633 633 ipc_answer_0(rid, ENOTSUP); -
uspace/srv/vfs/vfs.c
r4198f9c3 r852b801 108 108 vfs_truncate(callid, &call); 109 109 break; 110 case VFS_IN_FSTAT: 111 vfs_fstat(callid, &call); 112 break; 113 case VFS_IN_STAT: 114 vfs_stat(callid, &call); 115 break; 110 116 case VFS_IN_MKDIR: 111 117 vfs_mkdir(callid, &call); … … 117 123 vfs_rename(callid, &call); 118 124 break; 119 case VFS_IN_DEVICE:120 vfs_device(callid, &call);121 break;122 125 case VFS_IN_SYNC: 123 126 vfs_sync(callid, &call); 124 break;125 case VFS_IN_NODE:126 vfs_node(callid, &call);127 127 break; 128 128 default: -
uspace/srv/vfs/vfs.h
r4198f9c3 r852b801 199 199 extern void vfs_open(ipc_callid_t, ipc_call_t *); 200 200 extern void vfs_open_node(ipc_callid_t, ipc_call_t *); 201 extern void vfs_device(ipc_callid_t, ipc_call_t *);202 201 extern void vfs_sync(ipc_callid_t, ipc_call_t *); 203 extern void vfs_node(ipc_callid_t, ipc_call_t *);204 202 extern void vfs_close(ipc_callid_t, ipc_call_t *); 205 203 extern void vfs_read(ipc_callid_t, ipc_call_t *); … … 207 205 extern void vfs_seek(ipc_callid_t, ipc_call_t *); 208 206 extern void vfs_truncate(ipc_callid_t, ipc_call_t *); 207 extern void vfs_fstat(ipc_callid_t, ipc_call_t *); 208 extern void vfs_fstat(ipc_callid_t, ipc_call_t *); 209 extern void vfs_stat(ipc_callid_t, ipc_call_t *); 209 210 extern void vfs_mkdir(ipc_callid_t, ipc_call_t *); 210 211 extern void vfs_unlink(ipc_callid_t, ipc_call_t *); -
uspace/srv/vfs/vfs_ops.c
r4198f9c3 r852b801 642 642 } 643 643 644 void vfs_node(ipc_callid_t rid, ipc_call_t *request)645 {646 int fd = IPC_GET_ARG1(*request);647 648 /* Lookup the file structure corresponding to the file descriptor. */649 vfs_file_t *file = vfs_file_get(fd);650 if (!file) {651 ipc_answer_0(rid, ENOENT);652 return;653 }654 655 ipc_answer_3(rid, EOK, file->node->fs_handle, file->node->dev_handle,656 file->node->index);657 }658 659 void vfs_device(ipc_callid_t rid, ipc_call_t *request)660 {661 int fd = IPC_GET_ARG1(*request);662 663 /* Lookup the file structure corresponding to the file descriptor. */664 vfs_file_t *file = vfs_file_get(fd);665 if (!file) {666 ipc_answer_0(rid, ENOENT);667 return;668 }669 670 /*671 * Lock the open file structure so that no other thread can manipulate672 * the same open file at a time.673 */674 fibril_mutex_lock(&file->lock);675 int fs_phone = vfs_grab_phone(file->node->fs_handle);676 677 /* Make a VFS_OUT_DEVICE request at the destination FS server. */678 aid_t msg;679 ipc_call_t answer;680 msg = async_send_2(fs_phone, VFS_OUT_DEVICE, file->node->dev_handle,681 file->node->index, &answer);682 683 /* Wait for reply from the FS server. */684 ipcarg_t rc;685 async_wait_for(msg, &rc);686 687 vfs_release_phone(fs_phone);688 fibril_mutex_unlock(&file->lock);689 690 ipc_answer_1(rid, EOK, IPC_GET_ARG1(answer));691 }692 693 644 void vfs_sync(ipc_callid_t rid, ipc_call_t *request) 694 645 { … … 975 926 fibril_mutex_unlock(&file->lock); 976 927 ipc_answer_0(rid, (ipcarg_t)rc); 928 } 929 930 void vfs_fstat(ipc_callid_t rid, ipc_call_t *request) 931 { 932 int fd = IPC_GET_ARG1(*request); 933 size_t size = IPC_GET_ARG2(*request); 934 ipcarg_t rc; 935 936 vfs_file_t *file = vfs_file_get(fd); 937 if (!file) { 938 ipc_answer_0(rid, ENOENT); 939 return; 940 } 941 942 ipc_callid_t callid; 943 if (!ipc_data_read_receive(&callid, NULL)) { 944 ipc_answer_0(callid, EINVAL); 945 ipc_answer_0(rid, EINVAL); 946 return; 947 } 948 949 fibril_mutex_lock(&file->lock); 950 951 int fs_phone = vfs_grab_phone(file->node->fs_handle); 952 953 aid_t msg; 954 msg = async_send_3(fs_phone, VFS_OUT_STAT, file->node->dev_handle, 955 file->node->index, true, NULL); 956 ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 957 async_wait_for(msg, &rc); 958 vfs_release_phone(fs_phone); 959 960 fibril_mutex_unlock(&file->lock); 961 ipc_answer_0(rid, rc); 962 } 963 964 void vfs_stat(ipc_callid_t rid, ipc_call_t *request) 965 { 977 966 } 978 967
Note:
See TracChangeset
for help on using the changeset viewer.