Rev 4537 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4537 | Rev 4668 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | #include <stdio.h> |
42 | #include <stdio.h> |
43 | #include <stdlib.h> |
43 | #include <stdlib.h> |
44 | #include <string.h> |
44 | #include <string.h> |
45 | #include <bool.h> |
45 | #include <bool.h> |
46 | #include <futex.h> |
- | |
47 | #include <fibril_sync.h> |
46 | #include <fibril_sync.h> |
48 | #include <adt/list.h> |
47 | #include <adt/list.h> |
49 | #include <unistd.h> |
48 | #include <unistd.h> |
50 | #include <ctype.h> |
49 | #include <ctype.h> |
51 | #include <fcntl.h> |
50 | #include <fcntl.h> |
Line 53... | Line 52... | ||
53 | #include <vfs/canonify.h> |
52 | #include <vfs/canonify.h> |
54 | 53 | ||
55 | /* Forward declarations of static functions. */ |
54 | /* Forward declarations of static functions. */ |
56 | static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t); |
55 | static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t); |
57 | 56 | ||
58 | /** Pending mount structure. */ |
- | |
59 | typedef struct { |
- | |
60 | link_t link; |
- | |
61 | char *fs_name; /**< File system name */ |
- | |
62 | char *mp; /**< Mount point */ |
- | |
63 | char *opts; /**< Mount options. */ |
- | |
64 | ipc_callid_t callid; /**< Call ID waiting for the mount */ |
- | |
65 | ipc_callid_t rid; /**< Request ID */ |
- | |
66 | dev_handle_t dev_handle; /**< Device handle */ |
- | |
67 | } pending_req_t; |
- | |
68 | - | ||
69 | FIBRIL_MUTEX_INITIALIZE(pending_lock); |
- | |
70 | LIST_INITIALIZE(pending_req); |
- | |
71 | - | ||
72 | /** |
57 | /** |
73 | * This rwlock prevents the race between a triplet-to-VFS-node resolution and a |
58 | * This rwlock prevents the race between a triplet-to-VFS-node resolution and a |
74 | * concurrent VFS operation which modifies the file system namespace. |
59 | * concurrent VFS operation which modifies the file system namespace. |
75 | */ |
60 | */ |
76 | FIBRIL_RWLOCK_INITIALIZE(namespace_rwlock); |
61 | FIBRIL_RWLOCK_INITIALIZE(namespace_rwlock); |
Line 121... | Line 106... | ||
121 | return; |
106 | return; |
122 | } |
107 | } |
123 | 108 | ||
124 | /* |
109 | /* |
125 | * Now we hold a reference to mp_node. |
110 | * Now we hold a reference to mp_node. |
126 | * It will be dropped upon the corresponding VFS_UNMOUNT. |
111 | * It will be dropped upon the corresponding VFS_IN_UNMOUNT. |
127 | * This prevents the mount point from being deleted. |
112 | * This prevents the mount point from being deleted. |
128 | */ |
113 | */ |
129 | } else { |
114 | } else { |
130 | /* We still don't have the root file system mounted. */ |
115 | /* We still don't have the root file system mounted. */ |
131 | if (str_cmp(mp, "/") == 0) { |
116 | if (str_cmp(mp, "/") == 0) { |
Line 134... | Line 119... | ||
134 | * we are almost done. |
119 | * we are almost done. |
135 | */ |
120 | */ |
136 | 121 | ||
137 | /* Tell the mountee that it is being mounted. */ |
122 | /* Tell the mountee that it is being mounted. */ |
138 | phone = vfs_grab_phone(fs_handle); |
123 | phone = vfs_grab_phone(fs_handle); |
139 | msg = async_send_1(phone, VFS_MOUNTED, |
124 | msg = async_send_1(phone, VFS_OUT_MOUNTED, |
140 | (ipcarg_t) dev_handle, &answer); |
125 | (ipcarg_t) dev_handle, &answer); |
141 | /* send the mount options */ |
126 | /* send the mount options */ |
142 | rc = ipc_data_write_start(phone, (void *)opts, |
127 | rc = ipc_data_write_start(phone, (void *)opts, |
143 | str_size(opts)); |
128 | str_size(opts)); |
144 | if (rc != EOK) { |
129 | if (rc != EOK) { |
145 | vfs_release_phone(phone); |
- | |
146 | async_wait_for(msg, NULL); |
130 | async_wait_for(msg, NULL); |
- | 131 | vfs_release_phone(phone); |
|
147 | fibril_rwlock_write_unlock(&namespace_rwlock); |
132 | fibril_rwlock_write_unlock(&namespace_rwlock); |
148 | ipc_answer_0(rid, rc); |
133 | ipc_answer_0(rid, rc); |
149 | return; |
134 | return; |
150 | } |
135 | } |
151 | vfs_release_phone(phone); |
- | |
152 | async_wait_for(msg, &rc); |
136 | async_wait_for(msg, &rc); |
- | 137 | vfs_release_phone(phone); |
|
153 | 138 | ||
154 | if (rc != EOK) { |
139 | if (rc != EOK) { |
155 | fibril_rwlock_write_unlock(&namespace_rwlock); |
140 | fibril_rwlock_write_unlock(&namespace_rwlock); |
156 | ipc_answer_0(rid, rc); |
141 | ipc_answer_0(rid, rc); |
157 | return; |
142 | return; |
Line 194... | Line 179... | ||
194 | * handles, and we know the mount point VFS node. |
179 | * handles, and we know the mount point VFS node. |
195 | */ |
180 | */ |
196 | 181 | ||
197 | int mountee_phone = vfs_grab_phone(fs_handle); |
182 | int mountee_phone = vfs_grab_phone(fs_handle); |
198 | assert(mountee_phone >= 0); |
183 | assert(mountee_phone >= 0); |
199 | vfs_release_phone(mountee_phone); |
- | |
200 | 184 | ||
201 | phone = vfs_grab_phone(mp_res.triplet.fs_handle); |
185 | phone = vfs_grab_phone(mp_res.triplet.fs_handle); |
202 | msg = async_send_4(phone, VFS_MOUNT, |
186 | msg = async_send_4(phone, VFS_OUT_MOUNT, |
203 | (ipcarg_t) mp_res.triplet.dev_handle, |
187 | (ipcarg_t) mp_res.triplet.dev_handle, |
204 | (ipcarg_t) mp_res.triplet.index, |
188 | (ipcarg_t) mp_res.triplet.index, |
205 | (ipcarg_t) fs_handle, |
189 | (ipcarg_t) fs_handle, |
206 | (ipcarg_t) dev_handle, &answer); |
190 | (ipcarg_t) dev_handle, &answer); |
207 | 191 | ||
208 | /* send connection */ |
192 | /* send connection */ |
209 | rc = async_req_1_0(phone, IPC_M_CONNECTION_CLONE, mountee_phone); |
193 | rc = async_req_1_0(phone, IPC_M_CONNECTION_CLONE, mountee_phone); |
210 | if (rc != EOK) { |
194 | if (rc != EOK) { |
211 | vfs_release_phone(phone); |
- | |
212 | async_wait_for(msg, NULL); |
195 | async_wait_for(msg, NULL); |
- | 196 | vfs_release_phone(mountee_phone); |
|
- | 197 | vfs_release_phone(phone); |
|
213 | /* Mount failed, drop reference to mp_node. */ |
198 | /* Mount failed, drop reference to mp_node. */ |
214 | if (mp_node) |
199 | if (mp_node) |
215 | vfs_node_put(mp_node); |
200 | vfs_node_put(mp_node); |
216 | ipc_answer_0(rid, rc); |
201 | ipc_answer_0(rid, rc); |
217 | fibril_rwlock_write_unlock(&namespace_rwlock); |
202 | fibril_rwlock_write_unlock(&namespace_rwlock); |
218 | return; |
203 | return; |
219 | } |
204 | } |
220 | 205 | ||
- | 206 | vfs_release_phone(mountee_phone); |
|
- | 207 | ||
221 | /* send the mount options */ |
208 | /* send the mount options */ |
222 | rc = ipc_data_write_start(phone, (void *)opts, str_size(opts)); |
209 | rc = ipc_data_write_start(phone, (void *)opts, str_size(opts)); |
223 | if (rc != EOK) { |
210 | if (rc != EOK) { |
224 | vfs_release_phone(phone); |
- | |
225 | async_wait_for(msg, NULL); |
211 | async_wait_for(msg, NULL); |
- | 212 | vfs_release_phone(phone); |
|
226 | /* Mount failed, drop reference to mp_node. */ |
213 | /* Mount failed, drop reference to mp_node. */ |
227 | if (mp_node) |
214 | if (mp_node) |
228 | vfs_node_put(mp_node); |
215 | vfs_node_put(mp_node); |
229 | fibril_rwlock_write_unlock(&namespace_rwlock); |
216 | fibril_rwlock_write_unlock(&namespace_rwlock); |
230 | ipc_answer_0(rid, rc); |
217 | ipc_answer_0(rid, rc); |
231 | return; |
218 | return; |
232 | } |
219 | } |
233 | vfs_release_phone(phone); |
- | |
234 | async_wait_for(msg, &rc); |
220 | async_wait_for(msg, &rc); |
- | 221 | vfs_release_phone(phone); |
|
235 | 222 | ||
236 | if (rc == EOK) { |
223 | if (rc == EOK) { |
237 | rindex = (fs_index_t) IPC_GET_ARG1(answer); |
224 | rindex = (fs_index_t) IPC_GET_ARG1(answer); |
238 | rsize = (size_t) IPC_GET_ARG2(answer); |
225 | rsize = (size_t) IPC_GET_ARG2(answer); |
239 | rlnkcnt = (unsigned) IPC_GET_ARG3(answer); |
226 | rlnkcnt = (unsigned) IPC_GET_ARG3(answer); |
Line 256... | Line 243... | ||
256 | 243 | ||
257 | ipc_answer_0(rid, rc); |
244 | ipc_answer_0(rid, rc); |
258 | fibril_rwlock_write_unlock(&namespace_rwlock); |
245 | fibril_rwlock_write_unlock(&namespace_rwlock); |
259 | } |
246 | } |
260 | 247 | ||
261 | /** Process pending mount requests */ |
- | |
262 | void vfs_process_pending_mount(void) |
- | |
263 | { |
- | |
264 | link_t *cur; |
- | |
265 | - | ||
266 | loop: |
- | |
267 | fibril_mutex_lock(&pending_lock); |
- | |
268 | for (cur = pending_req.next; cur != &pending_req; cur = cur->next) { |
- | |
269 | pending_req_t *pr = list_get_instance(cur, pending_req_t, link); |
- | |
270 | - | ||
271 | fs_handle_t fs_handle = fs_name_to_handle(pr->fs_name, true); |
- | |
272 | if (!fs_handle) |
- | |
273 | continue; |
- | |
274 | - | ||
275 | /* Acknowledge that we know fs_name. */ |
- | |
276 | ipc_answer_0(pr->callid, EOK); |
- | |
277 | - | ||
278 | /* Do the mount */ |
- | |
279 | vfs_mount_internal(pr->rid, pr->dev_handle, fs_handle, pr->mp, |
- | |
280 | pr->opts); |
- | |
281 | - | ||
282 | free(pr->fs_name); |
- | |
283 | free(pr->mp); |
- | |
284 | free(pr->opts); |
- | |
285 | list_remove(cur); |
- | |
286 | free(pr); |
- | |
287 | fibril_mutex_unlock(&pending_lock); |
- | |
288 | fibril_yield(); |
- | |
289 | goto loop; |
- | |
290 | } |
- | |
291 | fibril_mutex_unlock(&pending_lock); |
- | |
292 | } |
- | |
293 | - | ||
294 | void vfs_mount(ipc_callid_t rid, ipc_call_t *request) |
248 | void vfs_mount(ipc_callid_t rid, ipc_call_t *request) |
295 | { |
249 | { |
296 | /* |
250 | /* |
297 | * We expect the library to do the device-name to device-handle |
251 | * We expect the library to do the device-name to device-handle |
298 | * translation for us, thus the device handle will arrive as ARG1 |
252 | * translation for us, thus the device handle will arrive as ARG1 |
Line 442... | Line 396... | ||
442 | 396 | ||
443 | /* |
397 | /* |
444 | * Check if we know a file system with the same name as is in fs_name. |
398 | * Check if we know a file system with the same name as is in fs_name. |
445 | * This will also give us its file system handle. |
399 | * This will also give us its file system handle. |
446 | */ |
400 | */ |
- | 401 | fibril_mutex_lock(&fs_head_lock); |
|
- | 402 | fs_handle_t fs_handle; |
|
- | 403 | recheck: |
|
447 | fs_handle_t fs_handle = fs_name_to_handle(fs_name, true); |
404 | fs_handle = fs_name_to_handle(fs_name, false); |
448 | if (!fs_handle) { |
405 | if (!fs_handle) { |
449 | if (flags & IPC_FLAG_BLOCKING) { |
406 | if (flags & IPC_FLAG_BLOCKING) { |
450 | pending_req_t *pr; |
- | |
451 | - | ||
452 | /* Blocking mount, add to pending list */ |
- | |
453 | pr = (pending_req_t *) malloc(sizeof(pending_req_t)); |
- | |
454 | if (!pr) { |
- | |
455 | ipc_answer_0(callid, ENOMEM); |
- | |
456 | ipc_answer_0(rid, ENOMEM); |
- | |
457 | free(mp); |
- | |
458 | free(fs_name); |
- | |
459 | free(opts); |
- | |
460 | return; |
- | |
461 | } |
- | |
462 | - | ||
463 | pr->fs_name = fs_name; |
- | |
464 | pr->mp = mp; |
- | |
465 | pr->opts = opts; |
- | |
466 | pr->callid = callid; |
- | |
467 | pr->rid = rid; |
- | |
468 | pr->dev_handle = dev_handle; |
- | |
469 | link_initialize(&pr->link); |
- | |
470 | fibril_mutex_lock(&pending_lock); |
407 | fibril_condvar_wait(&fs_head_cv, &fs_head_lock); |
471 | list_append(&pr->link, &pending_req); |
- | |
472 | fibril_mutex_unlock(&pending_lock); |
- | |
473 | return; |
408 | goto recheck; |
474 | } |
409 | } |
475 | 410 | ||
- | 411 | fibril_mutex_unlock(&fs_head_lock); |
|
476 | ipc_answer_0(callid, ENOENT); |
412 | ipc_answer_0(callid, ENOENT); |
477 | ipc_answer_0(rid, ENOENT); |
413 | ipc_answer_0(rid, ENOENT); |
478 | free(mp); |
414 | free(mp); |
479 | free(fs_name); |
415 | free(fs_name); |
480 | free(opts); |
416 | free(opts); |
481 | return; |
417 | return; |
482 | } |
418 | } |
- | 419 | fibril_mutex_unlock(&fs_head_lock); |
|
483 | 420 | ||
484 | /* Acknowledge that we know fs_name. */ |
421 | /* Acknowledge that we know fs_name. */ |
485 | ipc_answer_0(callid, EOK); |
422 | ipc_answer_0(callid, EOK); |
486 | 423 | ||
487 | /* Do the mount */ |
424 | /* Do the mount */ |
Line 498... | Line 435... | ||
498 | return; |
435 | return; |
499 | } |
436 | } |
500 | 437 | ||
501 | /* |
438 | /* |
502 | * The POSIX interface is open(path, oflag, mode). |
439 | * The POSIX interface is open(path, oflag, mode). |
503 | * We can receive oflags and mode along with the VFS_OPEN call; the path |
440 | * We can receive oflags and mode along with the VFS_IN_OPEN call; |
504 | * will need to arrive in another call. |
441 | * the path will need to arrive in another call. |
505 | * |
442 | * |
506 | * We also receive one private, non-POSIX set of flags called lflag |
443 | * We also receive one private, non-POSIX set of flags called lflag |
507 | * used to pass information to vfs_lookup_internal(). |
444 | * used to pass information to vfs_lookup_internal(). |
508 | */ |
445 | */ |
509 | int lflag = IPC_GET_ARG1(*request); |
446 | int lflag = IPC_GET_ARG1(*request); |
Line 616... | Line 553... | ||
616 | /* |
553 | /* |
617 | * The following increase in reference count is for the fact that the |
554 | * The following increase in reference count is for the fact that the |
618 | * file is being opened and that a file structure is pointing to it. |
555 | * file is being opened and that a file structure is pointing to it. |
619 | * It is necessary so that the file will not disappear when |
556 | * It is necessary so that the file will not disappear when |
620 | * vfs_node_put() is called. The reference will be dropped by the |
557 | * vfs_node_put() is called. The reference will be dropped by the |
621 | * respective VFS_CLOSE. |
558 | * respective VFS_IN_CLOSE. |
622 | */ |
559 | */ |
623 | vfs_node_addref(node); |
560 | vfs_node_addref(node); |
624 | vfs_node_put(node); |
561 | vfs_node_put(node); |
625 | 562 | ||
626 | /* Success! Return the new file descriptor to the client. */ |
563 | /* Success! Return the new file descriptor to the client. */ |
Line 693... | Line 630... | ||
693 | /* |
630 | /* |
694 | * The following increase in reference count is for the fact that the |
631 | * The following increase in reference count is for the fact that the |
695 | * file is being opened and that a file structure is pointing to it. |
632 | * file is being opened and that a file structure is pointing to it. |
696 | * It is necessary so that the file will not disappear when |
633 | * It is necessary so that the file will not disappear when |
697 | * vfs_node_put() is called. The reference will be dropped by the |
634 | * vfs_node_put() is called. The reference will be dropped by the |
698 | * respective VFS_CLOSE. |
635 | * respective VFS_IN_CLOSE. |
699 | */ |
636 | */ |
700 | vfs_node_addref(node); |
637 | vfs_node_addref(node); |
701 | vfs_node_put(node); |
638 | vfs_node_put(node); |
702 | 639 | ||
703 | /* Success! Return the new file descriptor to the client. */ |
640 | /* Success! Return the new file descriptor to the client. */ |
704 | ipc_answer_1(rid, EOK, fd); |
641 | ipc_answer_1(rid, EOK, fd); |
705 | } |
642 | } |
706 | 643 | ||
707 | void vfs_node(ipc_callid_t rid, ipc_call_t *request) |
- | |
708 | { |
- | |
709 | int fd = IPC_GET_ARG1(*request); |
- | |
710 | - | ||
711 | /* Lookup the file structure corresponding to the file descriptor. */ |
- | |
712 | vfs_file_t *file = vfs_file_get(fd); |
- | |
713 | if (!file) { |
- | |
714 | ipc_answer_0(rid, ENOENT); |
- | |
715 | return; |
- | |
716 | } |
- | |
717 | - | ||
718 | ipc_answer_3(rid, EOK, file->node->fs_handle, file->node->dev_handle, |
- | |
719 | file->node->index); |
- | |
720 | } |
- | |
721 | - | ||
722 | void vfs_device(ipc_callid_t rid, ipc_call_t *request) |
- | |
723 | { |
- | |
724 | int fd = IPC_GET_ARG1(*request); |
- | |
725 | - | ||
726 | /* Lookup the file structure corresponding to the file descriptor. */ |
- | |
727 | vfs_file_t *file = vfs_file_get(fd); |
- | |
728 | if (!file) { |
- | |
729 | ipc_answer_0(rid, ENOENT); |
- | |
730 | return; |
- | |
731 | } |
- | |
732 | - | ||
733 | /* |
- | |
734 | * Lock the open file structure so that no other thread can manipulate |
- | |
735 | * the same open file at a time. |
- | |
736 | */ |
- | |
737 | fibril_mutex_lock(&file->lock); |
- | |
738 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
- | |
739 | - | ||
740 | /* Make a VFS_DEVICE request at the destination FS server. */ |
- | |
741 | aid_t msg; |
- | |
742 | ipc_call_t answer; |
- | |
743 | msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
- | |
744 | file->node->dev_handle, file->node->index, &answer); |
- | |
745 | - | ||
746 | vfs_release_phone(fs_phone); |
- | |
747 | - | ||
748 | /* Wait for reply from the FS server. */ |
- | |
749 | ipcarg_t rc; |
- | |
750 | async_wait_for(msg, &rc); |
- | |
751 | - | ||
752 | fibril_mutex_unlock(&file->lock); |
- | |
753 | - | ||
754 | ipc_answer_1(rid, EOK, IPC_GET_ARG1(answer)); |
- | |
755 | } |
- | |
756 | - | ||
757 | void vfs_sync(ipc_callid_t rid, ipc_call_t *request) |
644 | void vfs_sync(ipc_callid_t rid, ipc_call_t *request) |
758 | { |
645 | { |
759 | int fd = IPC_GET_ARG1(*request); |
646 | int fd = IPC_GET_ARG1(*request); |
760 | 647 | ||
761 | /* Lookup the file structure corresponding to the file descriptor. */ |
648 | /* Lookup the file structure corresponding to the file descriptor. */ |
Line 770... | Line 657... | ||
770 | * the same open file at a time. |
657 | * the same open file at a time. |
771 | */ |
658 | */ |
772 | fibril_mutex_lock(&file->lock); |
659 | fibril_mutex_lock(&file->lock); |
773 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
660 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
774 | 661 | ||
775 | /* Make a VFS_SYMC request at the destination FS server. */ |
662 | /* Make a VFS_OUT_SYMC request at the destination FS server. */ |
776 | aid_t msg; |
663 | aid_t msg; |
777 | ipc_call_t answer; |
664 | ipc_call_t answer; |
778 | msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
665 | msg = async_send_2(fs_phone, VFS_OUT_SYNC, file->node->dev_handle, |
779 | file->node->dev_handle, file->node->index, &answer); |
666 | file->node->index, &answer); |
780 | - | ||
781 | vfs_release_phone(fs_phone); |
- | |
782 | 667 | ||
783 | /* Wait for reply from the FS server. */ |
668 | /* Wait for reply from the FS server. */ |
784 | ipcarg_t rc; |
669 | ipcarg_t rc; |
785 | async_wait_for(msg, &rc); |
670 | async_wait_for(msg, &rc); |
786 | 671 | ||
- | 672 | vfs_release_phone(fs_phone); |
|
787 | fibril_mutex_unlock(&file->lock); |
673 | fibril_mutex_unlock(&file->lock); |
788 | 674 | ||
789 | ipc_answer_0(rid, rc); |
675 | ipc_answer_0(rid, rc); |
790 | } |
676 | } |
791 | 677 | ||
Line 803... | Line 689... | ||
803 | /* |
689 | /* |
804 | * Lock the open file structure so that no other thread can manipulate |
690 | * Lock the open file structure so that no other thread can manipulate |
805 | * the same open file at a time. |
691 | * the same open file at a time. |
806 | */ |
692 | */ |
807 | fibril_mutex_lock(&file->lock); |
693 | fibril_mutex_lock(&file->lock); |
808 | - | ||
809 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
694 | int fs_phone = vfs_grab_phone(file->node->fs_handle); |
810 | 695 | ||
811 | /* Make a VFS_CLOSE request at the destination FS server. */ |
696 | /* Make a VFS_OUT_CLOSE request at the destination FS server. */ |
812 | aid_t msg; |
697 | aid_t msg; |
813 | ipc_call_t answer; |
698 | ipc_call_t answer; |
814 | msg = async_send_2(fs_phone, IPC_GET_METHOD(*request), |
699 | msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle, |
815 | file->node->dev_handle, file->node->index, &answer); |
700 | file->node->index, &answer); |
816 | - | ||
817 | vfs_release_phone(fs_phone); |
- | |
818 | 701 | ||
819 | /* Wait for reply from the FS server. */ |
702 | /* Wait for reply from the FS server. */ |
820 | ipcarg_t rc; |
703 | ipcarg_t rc; |
821 | async_wait_for(msg, &rc); |
704 | async_wait_for(msg, &rc); |
822 | 705 | ||
- | 706 | vfs_release_phone(fs_phone); |
|
823 | fibril_mutex_unlock(&file->lock); |
707 | fibril_mutex_unlock(&file->lock); |
824 | 708 | ||
825 | int retval = IPC_GET_ARG1(answer); |
709 | int retval = IPC_GET_ARG1(answer); |
826 | if (retval != EOK) |
710 | if (retval != EOK) |
827 | ipc_answer_0(rid, retval); |
711 | ipc_answer_0(rid, retval); |
Line 897... | Line 781... | ||
897 | /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */ |
781 | /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */ |
898 | aid_t msg; |
782 | aid_t msg; |
899 | ipc_call_t answer; |
783 | ipc_call_t answer; |
900 | if (!read && file->append) |
784 | if (!read && file->append) |
901 | file->pos = file->node->size; |
785 | file->pos = file->node->size; |
902 | msg = async_send_3(fs_phone, IPC_GET_METHOD(*request), |
786 | msg = async_send_3(fs_phone, read ? VFS_OUT_READ : VFS_OUT_WRITE, |
903 | file->node->dev_handle, file->node->index, file->pos, &answer); |
787 | file->node->dev_handle, file->node->index, file->pos, &answer); |
904 | 788 | ||
905 | /* |
789 | /* |
906 | * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the |
790 | * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the |
907 | * destination FS server. The call will be routed as if sent by |
791 | * destination FS server. The call will be routed as if sent by |
908 | * ourselves. Note that call arguments are immutable in this case so we |
792 | * ourselves. Note that call arguments are immutable in this case so we |
909 | * don't have to bother. |
793 | * don't have to bother. |
910 | */ |
794 | */ |
911 | ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
795 | ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
912 | 796 | ||
913 | vfs_release_phone(fs_phone); |
- | |
914 | - | ||
915 | /* Wait for reply from the FS server. */ |
797 | /* Wait for reply from the FS server. */ |
916 | ipcarg_t rc; |
798 | ipcarg_t rc; |
917 | async_wait_for(msg, &rc); |
799 | async_wait_for(msg, &rc); |
918 | 800 | ||
- | 801 | vfs_release_phone(fs_phone); |
|
- | 802 | ||
919 | size_t bytes = IPC_GET_ARG1(answer); |
803 | size_t bytes = IPC_GET_ARG1(answer); |
920 | 804 | ||
921 | if (file->node->type == VFS_NODE_DIRECTORY) |
805 | if (file->node->type == VFS_NODE_DIRECTORY) |
922 | fibril_rwlock_read_unlock(&namespace_rwlock); |
806 | fibril_rwlock_read_unlock(&namespace_rwlock); |
923 | 807 | ||
Line 1011... | Line 895... | ||
1011 | { |
895 | { |
1012 | ipcarg_t rc; |
896 | ipcarg_t rc; |
1013 | int fs_phone; |
897 | int fs_phone; |
1014 | 898 | ||
1015 | fs_phone = vfs_grab_phone(fs_handle); |
899 | fs_phone = vfs_grab_phone(fs_handle); |
1016 | rc = async_req_3_0(fs_phone, VFS_TRUNCATE, (ipcarg_t)dev_handle, |
900 | rc = async_req_3_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t)dev_handle, |
1017 | (ipcarg_t)index, (ipcarg_t)size); |
901 | (ipcarg_t)index, (ipcarg_t)size); |
1018 | vfs_release_phone(fs_phone); |
902 | vfs_release_phone(fs_phone); |
1019 | return (int)rc; |
903 | return (int)rc; |
1020 | } |
904 | } |
1021 | 905 | ||
Line 1041... | Line 925... | ||
1041 | 925 | ||
1042 | fibril_mutex_unlock(&file->lock); |
926 | fibril_mutex_unlock(&file->lock); |
1043 | ipc_answer_0(rid, (ipcarg_t)rc); |
927 | ipc_answer_0(rid, (ipcarg_t)rc); |
1044 | } |
928 | } |
1045 | 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 | { |
|
- | 966 | size_t len; |
|
- | 967 | ipc_callid_t callid; |
|
- | 968 | ||
- | 969 | if (!ipc_data_write_receive(&callid, &len)) { |
|
- | 970 | ipc_answer_0(callid, EINVAL); |
|
- | 971 | ipc_answer_0(rid, EINVAL); |
|
- | 972 | return; |
|
- | 973 | } |
|
- | 974 | char *path = malloc(len + 1); |
|
- | 975 | if (!path) { |
|
- | 976 | ipc_answer_0(callid, ENOMEM); |
|
- | 977 | ipc_answer_0(rid, ENOMEM); |
|
- | 978 | return; |
|
- | 979 | } |
|
- | 980 | int rc; |
|
- | 981 | if ((rc = ipc_data_write_finalize(callid, path, len))) { |
|
- | 982 | ipc_answer_0(rid, rc); |
|
- | 983 | free(path); |
|
- | 984 | return; |
|
- | 985 | } |
|
- | 986 | path[len] = '\0'; |
|
- | 987 | ||
- | 988 | if (!ipc_data_read_receive(&callid, NULL)) { |
|
- | 989 | free(path); |
|
- | 990 | ipc_answer_0(callid, EINVAL); |
|
- | 991 | ipc_answer_0(rid, EINVAL); |
|
- | 992 | return; |
|
- | 993 | } |
|
- | 994 | ||
- | 995 | vfs_lookup_res_t lr; |
|
- | 996 | fibril_rwlock_read_lock(&namespace_rwlock); |
|
- | 997 | rc = vfs_lookup_internal(path, L_NONE, &lr, NULL); |
|
- | 998 | free(path); |
|
- | 999 | if (rc != EOK) { |
|
- | 1000 | fibril_rwlock_read_unlock(&namespace_rwlock); |
|
- | 1001 | ipc_answer_0(callid, rc); |
|
- | 1002 | ipc_answer_0(rid, rc); |
|
- | 1003 | return; |
|
- | 1004 | } |
|
- | 1005 | vfs_node_t *node = vfs_node_get(&lr); |
|
- | 1006 | if (!node) { |
|
- | 1007 | fibril_rwlock_read_unlock(&namespace_rwlock); |
|
- | 1008 | ipc_answer_0(callid, ENOMEM); |
|
- | 1009 | ipc_answer_0(rid, ENOMEM); |
|
- | 1010 | return; |
|
- | 1011 | } |
|
- | 1012 | ||
- | 1013 | fibril_rwlock_read_unlock(&namespace_rwlock); |
|
- | 1014 | ||
- | 1015 | int fs_phone = vfs_grab_phone(node->fs_handle); |
|
- | 1016 | aid_t msg; |
|
- | 1017 | msg = async_send_3(fs_phone, VFS_OUT_STAT, node->dev_handle, |
|
- | 1018 | node->index, false, NULL); |
|
- | 1019 | ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); |
|
- | 1020 | ||
- | 1021 | ipcarg_t rv; |
|
- | 1022 | async_wait_for(msg, &rv); |
|
- | 1023 | vfs_release_phone(fs_phone); |
|
- | 1024 | ||
- | 1025 | ipc_answer_0(rid, rv); |
|
- | 1026 | ||
- | 1027 | vfs_node_put(node); |
|
- | 1028 | } |
|
- | 1029 | ||
1046 | void vfs_mkdir(ipc_callid_t rid, ipc_call_t *request) |
1030 | void vfs_mkdir(ipc_callid_t rid, ipc_call_t *request) |
1047 | { |
1031 | { |
1048 | int mode = IPC_GET_ARG1(*request); |
1032 | int mode = IPC_GET_ARG1(*request); |
1049 | 1033 | ||
1050 | size_t len; |
1034 | size_t len; |
Line 1115... | Line 1099... | ||
1115 | } |
1099 | } |
1116 | 1100 | ||
1117 | /* |
1101 | /* |
1118 | * The name has already been unlinked by vfs_lookup_internal(). |
1102 | * The name has already been unlinked by vfs_lookup_internal(). |
1119 | * We have to get and put the VFS node to ensure that it is |
1103 | * We have to get and put the VFS node to ensure that it is |
1120 | * VFS_DESTROY'ed after the last reference to it is dropped. |
1104 | * VFS_OUT_DESTROY'ed after the last reference to it is dropped. |
1121 | */ |
1105 | */ |
1122 | vfs_node_t *node = vfs_node_get(&lr); |
1106 | vfs_node_t *node = vfs_node_get(&lr); |
1123 | futex_down(&nodes_futex); |
1107 | fibril_mutex_lock(&nodes_mutex); |
1124 | node->lnkcnt--; |
1108 | node->lnkcnt--; |
1125 | futex_up(&nodes_futex); |
1109 | fibril_mutex_unlock(&nodes_mutex); |
1126 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1110 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1127 | vfs_node_put(node); |
1111 | vfs_node_put(node); |
1128 | ipc_answer_0(rid, EOK); |
1112 | ipc_answer_0(rid, EOK); |
1129 | } |
1113 | } |
1130 | 1114 | ||
Line 1269... | Line 1253... | ||
1269 | ipc_answer_0(rid, ENOMEM); |
1253 | ipc_answer_0(rid, ENOMEM); |
1270 | free(old); |
1254 | free(old); |
1271 | free(new); |
1255 | free(new); |
1272 | return; |
1256 | return; |
1273 | } |
1257 | } |
1274 | futex_down(&nodes_futex); |
1258 | fibril_mutex_lock(&nodes_mutex); |
1275 | new_node->lnkcnt--; |
1259 | new_node->lnkcnt--; |
1276 | futex_up(&nodes_futex); |
1260 | fibril_mutex_unlock(&nodes_mutex); |
1277 | break; |
1261 | break; |
1278 | default: |
1262 | default: |
1279 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1263 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1280 | ipc_answer_0(rid, ENOTEMPTY); |
1264 | ipc_answer_0(rid, ENOTEMPTY); |
1281 | free(old); |
1265 | free(old); |
Line 1291... | Line 1275... | ||
1291 | ipc_answer_0(rid, rc); |
1275 | ipc_answer_0(rid, rc); |
1292 | free(old); |
1276 | free(old); |
1293 | free(new); |
1277 | free(new); |
1294 | return; |
1278 | return; |
1295 | } |
1279 | } |
1296 | futex_down(&nodes_futex); |
1280 | fibril_mutex_lock(&nodes_mutex); |
1297 | old_node->lnkcnt++; |
1281 | old_node->lnkcnt++; |
1298 | futex_up(&nodes_futex); |
1282 | fibril_mutex_unlock(&nodes_mutex); |
1299 | /* Destroy the link for the old name. */ |
1283 | /* Destroy the link for the old name. */ |
1300 | rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); |
1284 | rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); |
1301 | if (rc != EOK) { |
1285 | if (rc != EOK) { |
1302 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1286 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1303 | vfs_node_put(old_node); |
1287 | vfs_node_put(old_node); |
Line 1306... | Line 1290... | ||
1306 | ipc_answer_0(rid, rc); |
1290 | ipc_answer_0(rid, rc); |
1307 | free(old); |
1291 | free(old); |
1308 | free(new); |
1292 | free(new); |
1309 | return; |
1293 | return; |
1310 | } |
1294 | } |
1311 | futex_down(&nodes_futex); |
1295 | fibril_mutex_lock(&nodes_mutex); |
1312 | old_node->lnkcnt--; |
1296 | old_node->lnkcnt--; |
1313 | futex_up(&nodes_futex); |
1297 | fibril_mutex_unlock(&nodes_mutex); |
1314 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1298 | fibril_rwlock_write_unlock(&namespace_rwlock); |
1315 | vfs_node_put(old_node); |
1299 | vfs_node_put(old_node); |
1316 | if (new_node) |
1300 | if (new_node) |
1317 | vfs_node_put(new_node); |
1301 | vfs_node_put(new_node); |
1318 | free(old); |
1302 | free(old); |