Changeset ff8c87c in mainline
- Timestamp:
- 2013-07-24T22:51:59Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0ed9cb6
- Parents:
- 9b48c06
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/trace/trace.c
r9b48c06 rff8c87c 696 696 697 697 p = proto_new("vfs"); 698 o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);699 proto_add_oper(p, VFS_IN_OPEN, o);700 698 o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); 701 699 proto_add_oper(p, VFS_IN_READ, o); … … 724 722 o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def); 725 723 proto_add_oper(p, VFS_IN_STAT, o); 724 o = oper_new("walk", 3, arg_def, V_INT_ERRNO, 0, resp_def); 725 proto_add_oper(p, VFS_IN_WALK, o); 726 o = oper_new("open2", 2, arg_def, V_ERRNO, 0, resp_def); 727 proto_add_oper(p, VFS_IN_OPEN2, o); 726 728 727 729 proto_register(SERVICE_VFS, p); -
uspace/lib/c/include/ipc/vfs.h
r9b48c06 rff8c87c 63 63 64 64 typedef enum { 65 VFS_IN_OPEN = IPC_FIRST_USER_METHOD, 66 VFS_IN_READ, 65 VFS_IN_READ = IPC_FIRST_USER_METHOD, 67 66 VFS_IN_WRITE, 68 67 VFS_IN_SEEK, -
uspace/srv/vfs/vfs.c
r9b48c06 rff8c87c 91 91 vfs_open2(callid, &call); 92 92 break; 93 case VFS_IN_OPEN:94 vfs_open(callid, &call);95 break;96 93 case VFS_IN_CLOSE: 97 94 vfs_close(callid, &call); -
uspace/srv/vfs/vfs.h
r9b48c06 rff8c87c 211 211 extern void vfs_mount(ipc_callid_t, ipc_call_t *); 212 212 extern void vfs_unmount(ipc_callid_t, ipc_call_t *); 213 extern void vfs_open(ipc_callid_t, ipc_call_t *);214 213 extern void vfs_sync(ipc_callid_t, ipc_call_t *); 215 214 extern void vfs_dup(ipc_callid_t, ipc_call_t *); -
uspace/srv/vfs/vfs_ops.c
r9b48c06 rff8c87c 738 738 } 739 739 740 void vfs_open(ipc_callid_t rid, ipc_call_t *request)741 {742 /*743 * The POSIX interface is open(path, oflag, mode).744 * We can receive oflags and mode along with the VFS_IN_OPEN call;745 * the path will need to arrive in another call.746 *747 * We also receive one private, non-POSIX set of flags called lflag748 * used to pass information to vfs_lookup_internal().749 */750 int lflag = IPC_GET_ARG1(*request);751 int oflag = IPC_GET_ARG2(*request);752 int mode = IPC_GET_ARG3(*request);753 754 /* Ignore mode for now. */755 (void) mode;756 757 /*758 * Make sure that we are called with exactly one of L_FILE and759 * L_DIRECTORY. Make sure that the user does not pass L_OPEN,760 * L_ROOT or L_MP.761 */762 if (((lflag & (L_FILE | L_DIRECTORY)) == 0) ||763 ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) ||764 (lflag & (L_OPEN | L_ROOT | L_MP))) {765 async_answer_0(rid, EINVAL);766 return;767 }768 769 if ((((oflag & O_RDONLY) != 0) + ((oflag & O_WRONLY) != 0) + ((oflag & O_RDWR) != 0)) != 1) {770 async_answer_0(rid, EINVAL);771 return;772 }773 774 if (oflag & O_CREAT)775 lflag |= L_CREATE;776 if (oflag & O_EXCL)777 lflag |= L_EXCLUSIVE;778 779 char *path;780 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);781 if (rc != EOK) {782 async_answer_0(rid, rc);783 return;784 }785 786 /*787 * Avoid the race condition in which the file can be deleted before we788 * find/create-and-lock the VFS node corresponding to the looked-up789 * triplet.790 */791 if (lflag & L_CREATE)792 fibril_rwlock_write_lock(&namespace_rwlock);793 else794 fibril_rwlock_read_lock(&namespace_rwlock);795 796 /* The path is now populated and we can call vfs_lookup_internal(). */797 vfs_lookup_res_t lr;798 rc = vfs_lookup_internal(path, lflag | L_OPEN, &lr, NULL);799 if (rc != EOK) {800 if (lflag & L_CREATE)801 fibril_rwlock_write_unlock(&namespace_rwlock);802 else803 fibril_rwlock_read_unlock(&namespace_rwlock);804 async_answer_0(rid, rc);805 free(path);806 return;807 }808 809 /* Path is no longer needed. */810 free(path);811 812 vfs_node_t *node = vfs_node_get(&lr);813 if (lflag & L_CREATE)814 fibril_rwlock_write_unlock(&namespace_rwlock);815 else816 fibril_rwlock_read_unlock(&namespace_rwlock);817 818 /* Truncate the file if requested and if necessary. */819 if (oflag & O_TRUNC) {820 fibril_rwlock_write_lock(&node->contents_rwlock);821 if (node->size) {822 rc = vfs_truncate_internal(node->fs_handle,823 node->service_id, node->index, 0);824 if (rc) {825 fibril_rwlock_write_unlock(&node->contents_rwlock);826 vfs_node_put(node);827 async_answer_0(rid, rc);828 return;829 }830 node->size = 0;831 }832 fibril_rwlock_write_unlock(&node->contents_rwlock);833 }834 835 /*836 * Get ourselves a file descriptor and the corresponding vfs_file_t837 * structure.838 */839 int fd = vfs_fd_alloc((oflag & O_DESC) != 0);840 if (fd < 0) {841 vfs_node_put(node);842 async_answer_0(rid, fd);843 return;844 }845 vfs_file_t *file = vfs_file_get(fd);846 847 /* FIXME: There is a potential race with another fibril of a malicious client. */848 assert(file);849 850 file->node = node;851 if (oflag & O_RDONLY)852 file->open_read = true;853 if (oflag & O_WRONLY)854 file->open_write = true;855 if (oflag & O_RDWR)856 file->open_read = file->open_write = true;857 if (oflag & O_APPEND)858 file->append = true;859 assert(file->open_read || file->open_write);860 861 /*862 * The following increase in reference count is for the fact that the863 * file is being opened and that a file structure is pointing to it.864 * It is necessary so that the file will not disappear when865 * vfs_node_put() is called. The reference will be dropped by the866 * respective VFS_IN_CLOSE.867 */868 vfs_node_addref(node);869 vfs_node_put(node);870 vfs_file_put(file);871 872 /* Success! Return the new file descriptor to the client. */873 async_answer_1(rid, EOK, fd);874 }875 876 740 void vfs_sync(ipc_callid_t rid, ipc_call_t *request) 877 741 {
Note:
See TracChangeset
for help on using the changeset viewer.