static void notification_received(ipc_callid_t callid, ipc_call_t *call) { switch (IPC_GET_IMETHOD(*call)) { case VFS_TASK_STATE_CHANGE: if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE) vfs_pass_handle( (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call), IPC_GET_ARG5(*call)), call->in_task_id, (int) IPC_GET_ARG2(*call)); break; default: break; } }
int bd_get_num_blocks(bd_t *bd, aoff64_t *rnb) { sysarg_t nb_l; sysarg_t nb_h; async_exch_t *exch = async_exchange_begin(bd->sess); int rc = async_req_0_2(exch, BD_GET_NUM_BLOCKS, &nb_l, &nb_h); async_exchange_end(exch); if (rc != EOK) return rc; *rnb = (aoff64_t) MERGE_LOUP32(nb_l, nb_h); return EOK; }
static void fault_event(ipc_callid_t callid, ipc_call_t *call) { const char *fname; char *s_taskid; int rc; task_id_t taskid; uintptr_t thread; taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); thread = IPC_GET_ARG3(*call); if (asprintf(&s_taskid, "%" PRIu64, taskid) < 0) { printf("Memory allocation failed.\n"); return; } printf(NAME ": Task %" PRIu64 " fault in thread %p.\n", taskid, (void *) thread); fname = "/app/taskdump"; #ifdef CONFIG_WRITE_CORE_FILES char *dump_fname; if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) { printf("Memory allocation failed.\n"); return; } printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid); rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid, NULL); #else printf(NAME ": Executing %s -t %s\n", fname, s_taskid); rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL); #endif if (rc != EOK) { printf("%s: Error spawning %s (%s).\n", NAME, fname, str_error(rc)); } }
static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) { void *fs_va = NULL; ipc_callid_t callid; ipc_call_t call; sysarg_t method; size_t comm_size; unsigned int flags; int retval; uint64_t ba; size_t cnt; /* Answer the IPC_M_CONNECT_ME_TO call. */ async_answer_0(iid, EOK); if (!async_share_out_receive(&callid, &comm_size, &flags)) { async_answer_0(callid, EHANGUP); return; } (void) async_share_out_finalize(callid, &fs_va); if (fs_va == AS_MAP_FAILED) { async_answer_0(callid, EHANGUP); return; } while (true) { callid = async_get_call(&call); method = IPC_GET_IMETHOD(call); if (!method) { /* The other side has hung up. */ async_answer_0(callid, EOK); return; } switch (method) { case BD_READ_BLOCKS: ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); cnt = IPC_GET_ARG3(call); if (cnt * block_size > comm_size) { retval = ELIMIT; break; } retval = file_bd_read_blocks(ba, cnt, fs_va); break; case BD_WRITE_BLOCKS: ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); cnt = IPC_GET_ARG3(call); if (cnt * block_size > comm_size) { retval = ELIMIT; break; } retval = file_bd_write_blocks(ba, cnt, fs_va); break; case BD_GET_BLOCK_SIZE: async_answer_1(callid, EOK, block_size); continue; case BD_GET_NUM_BLOCKS: async_answer_2(callid, EOK, LOWER32(num_blocks), UPPER32(num_blocks)); continue; default: retval = EINVAL; break; } async_answer_0(callid, retval); } }
/** Perform a path lookup. * * @param path Path to be resolved; it must be a NULL-terminated * string. * @param lflag Flags to be used during lookup. * @param result Empty structure where the lookup result will be stored. * Can be NULL. * @param altroot If non-empty, will be used instead of rootfs as the root * of the whole VFS tree. * * @return EOK on success or an error code from errno.h. * */ int vfs_lookup_internal(char *path, int lflag, vfs_lookup_res_t *result, vfs_pair_t *altroot, ...) { vfs_pair_t *root; if (altroot) root = altroot; else root = &rootfs; if (!root->fs_handle) return ENOENT; size_t len; path = canonify(path, &len); if (!path) return EINVAL; fs_index_t index = 0; if (lflag & L_LINK) { va_list ap; va_start(ap, altroot); index = va_arg(ap, fs_index_t); va_end(ap); } fibril_mutex_lock(&plb_mutex); plb_entry_t entry; link_initialize(&entry.plb_link); entry.len = len; size_t first; /* the first free index */ size_t last; /* the last free index */ if (list_empty(&plb_entries)) { first = 0; last = PLB_SIZE - 1; } else { plb_entry_t *oldest = list_get_instance( list_first(&plb_entries), plb_entry_t, plb_link); plb_entry_t *newest = list_get_instance( list_last(&plb_entries), plb_entry_t, plb_link); first = (newest->index + newest->len) % PLB_SIZE; last = (oldest->index - 1) % PLB_SIZE; } if (first <= last) { if ((last - first) + 1 < len) { /* * The buffer cannot absorb the path. */ fibril_mutex_unlock(&plb_mutex); return ELIMIT; } } else { if (PLB_SIZE - ((first - last) + 1) < len) { /* * The buffer cannot absorb the path. */ fibril_mutex_unlock(&plb_mutex); return ELIMIT; } } /* * We know the first free index in PLB and we also know that there is * enough space in the buffer to hold our path. */ entry.index = first; entry.len = len; /* * Claim PLB space by inserting the entry into the PLB entry ring * buffer. */ list_append(&entry.plb_link, &plb_entries); fibril_mutex_unlock(&plb_mutex); /* * Copy the path into PLB. */ size_t cnt1 = min(len, (PLB_SIZE - first) + 1); size_t cnt2 = len - cnt1; memcpy(&plb[first], path, cnt1); memcpy(plb, &path[cnt1], cnt2); ipc_call_t answer; async_exch_t *exch = vfs_exchange_grab(root->fs_handle); aid_t req = async_send_5(exch, VFS_OUT_LOOKUP, (sysarg_t) first, (sysarg_t) (first + len - 1) % PLB_SIZE, (sysarg_t) root->service_id, (sysarg_t) lflag, (sysarg_t) index, &answer); sysarg_t rc; async_wait_for(req, &rc); vfs_exchange_release(exch); fibril_mutex_lock(&plb_mutex); list_remove(&entry.plb_link); /* * Erasing the path from PLB will come handy for debugging purposes. */ memset(&plb[first], 0, cnt1); memset(plb, 0, cnt2); fibril_mutex_unlock(&plb_mutex); if ((int) rc < EOK) return (int) rc; if (!result) return EOK; result->triplet.fs_handle = (fs_handle_t) rc; result->triplet.service_id = (service_id_t) IPC_GET_ARG1(answer); result->triplet.index = (fs_index_t) IPC_GET_ARG2(answer); result->size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(answer), IPC_GET_ARG4(answer)); result->lnkcnt = (unsigned int) IPC_GET_ARG5(answer); if (lflag & L_FILE) result->type = VFS_NODE_FILE; else if (lflag & L_DIRECTORY) result->type = VFS_NODE_DIRECTORY; else result->type = VFS_NODE_UNKNOWN; return EOK; }
int main(int argc, char **argv) { printf("%s: HelenOS IPC Naming Service\n", NAME); int rc = service_init(); if (rc != EOK) return rc; rc = clonable_init(); if (rc != EOK) return rc; rc = task_init(); if (rc != EOK) return rc; printf("%s: Accepting connections\n", NAME); while (true) { process_pending_conn(); process_pending_wait(); ipc_call_t call; ipc_callid_t callid = ipc_wait_for_call(&call); task_id_t id; sysarg_t retval; switch (IPC_GET_IMETHOD(call)) { case IPC_M_PHONE_HUNGUP: retval = ns_task_disconnect(&call); break; case IPC_M_CONNECT_TO_ME: /* * Server requests service registration. */ if (service_clonable(IPC_GET_ARG1(call))) { register_clonable(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call, callid); continue; } else { retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call); } break; case IPC_M_CONNECT_ME_TO: /* * Client requests to be connected to a service. */ if (service_clonable(IPC_GET_ARG1(call))) { connect_to_clonable(IPC_GET_ARG1(call), &call, callid); continue; } else { connect_to_service(IPC_GET_ARG1(call), &call, callid); continue; } break; case NS_PING: retval = EOK; break; case NS_TASK_WAIT: id = (task_id_t) MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); wait_for_task(id, &call, callid); continue; case NS_ID_INTRO: retval = ns_task_id_intro(&call); break; case NS_RETVAL: retval = ns_task_retval(&call); break; default: retval = ENOENT; break; } if (!(callid & IPC_CALLID_NOTIFICATION)) ipc_answer_0(callid, retval); } /* Not reached */ return 0; }