Changes in uspace/lib/fs/libfs.c [b946bf83:5bf76c1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fs/libfs.c
rb946bf83 r5bf76c1 45 45 #include <mem.h> 46 46 #include <sys/stat.h> 47 #include <stdlib.h> 47 48 48 49 #define on_error(rc, action) \ … … 61 62 } while (0) 62 63 64 static fs_reg_t reg; 65 66 static vfs_out_ops_t *vfs_out_ops = NULL; 67 static libfs_ops_t *libfs_ops = NULL; 68 69 static void libfs_mount(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *); 70 static void libfs_unmount(libfs_ops_t *, ipc_callid_t, ipc_call_t *); 71 static void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, 72 ipc_call_t *); 73 static void libfs_stat(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *); 74 static void libfs_open_node(libfs_ops_t *, fs_handle_t, ipc_callid_t, 75 ipc_call_t *); 76 77 static void vfs_out_mounted(ipc_callid_t rid, ipc_call_t *req) 78 { 79 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 80 char *opts; 81 int rc; 82 83 /* Accept the mount options. */ 84 rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 85 if (rc != EOK) { 86 async_answer_0(rid, rc); 87 return; 88 } 89 90 fs_index_t index; 91 aoff64_t size; 92 unsigned lnkcnt; 93 rc = vfs_out_ops->mounted(service_id, opts, &index, &size, &lnkcnt); 94 95 if (rc == EOK) 96 async_answer_4(rid, EOK, index, LOWER32(size), UPPER32(size), 97 lnkcnt); 98 else 99 async_answer_0(rid, rc); 100 101 free(opts); 102 } 103 104 static void vfs_out_mount(ipc_callid_t rid, ipc_call_t *req) 105 { 106 libfs_mount(libfs_ops, reg.fs_handle, rid, req); 107 } 108 109 static void vfs_out_unmounted(ipc_callid_t rid, ipc_call_t *req) 110 { 111 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 112 int rc; 113 114 rc = vfs_out_ops->unmounted(service_id); 115 116 async_answer_0(rid, rc); 117 } 118 119 static void vfs_out_unmount(ipc_callid_t rid, ipc_call_t *req) 120 { 121 122 libfs_unmount(libfs_ops, rid, req); 123 } 124 125 static void vfs_out_lookup(ipc_callid_t rid, ipc_call_t *req) 126 { 127 libfs_lookup(libfs_ops, reg.fs_handle, rid, req); 128 } 129 130 static void vfs_out_read(ipc_callid_t rid, ipc_call_t *req) 131 { 132 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 133 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 134 aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req), 135 IPC_GET_ARG4(*req)); 136 size_t rbytes; 137 int rc; 138 139 rc = vfs_out_ops->read(service_id, index, pos, &rbytes); 140 141 if (rc == EOK) 142 async_answer_1(rid, EOK, rbytes); 143 else 144 async_answer_0(rid, rc); 145 } 146 147 static void vfs_out_write(ipc_callid_t rid, ipc_call_t *req) 148 { 149 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 150 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 151 aoff64_t pos = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req), 152 IPC_GET_ARG4(*req)); 153 size_t wbytes; 154 aoff64_t nsize; 155 int rc; 156 157 rc = vfs_out_ops->write(service_id, index, pos, &wbytes, &nsize); 158 159 if (rc == EOK) 160 async_answer_3(rid, EOK, wbytes, LOWER32(nsize), UPPER32(nsize)); 161 else 162 async_answer_0(rid, rc); 163 } 164 165 static void vfs_out_truncate(ipc_callid_t rid, ipc_call_t *req) 166 { 167 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 168 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 169 aoff64_t size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*req), 170 IPC_GET_ARG4(*req)); 171 int rc; 172 173 rc = vfs_out_ops->truncate(service_id, index, size); 174 175 async_answer_0(rid, rc); 176 } 177 178 static void vfs_out_close(ipc_callid_t rid, ipc_call_t *req) 179 { 180 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 181 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 182 int rc; 183 184 rc = vfs_out_ops->close(service_id, index); 185 186 async_answer_0(rid, rc); 187 } 188 189 static void vfs_out_destroy(ipc_callid_t rid, ipc_call_t *req) 190 { 191 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 192 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 193 int rc; 194 195 rc = vfs_out_ops->destroy(service_id, index); 196 197 async_answer_0(rid, rc); 198 } 199 200 static void vfs_out_open_node(ipc_callid_t rid, ipc_call_t *req) 201 { 202 libfs_open_node(libfs_ops, reg.fs_handle, rid, req); 203 } 204 205 static void vfs_out_stat(ipc_callid_t rid, ipc_call_t *req) 206 { 207 libfs_stat(libfs_ops, reg.fs_handle, rid, req); 208 } 209 210 static void vfs_out_sync(ipc_callid_t rid, ipc_call_t *req) 211 { 212 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req); 213 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*req); 214 int rc; 215 216 rc = vfs_out_ops->sync(service_id, index); 217 218 async_answer_0(rid, rc); 219 } 220 221 static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 222 { 223 if (iid) { 224 /* 225 * This only happens for connections opened by 226 * IPC_M_CONNECT_ME_TO calls as opposed to callback connections 227 * created by IPC_M_CONNECT_TO_ME. 228 */ 229 async_answer_0(iid, EOK); 230 } 231 232 while (true) { 233 ipc_call_t call; 234 ipc_callid_t callid = async_get_call(&call); 235 236 if (!IPC_GET_IMETHOD(call)) 237 return; 238 239 switch (IPC_GET_IMETHOD(call)) { 240 case VFS_OUT_MOUNTED: 241 vfs_out_mounted(callid, &call); 242 break; 243 case VFS_OUT_MOUNT: 244 vfs_out_mount(callid, &call); 245 break; 246 case VFS_OUT_UNMOUNTED: 247 vfs_out_unmounted(callid, &call); 248 break; 249 case VFS_OUT_UNMOUNT: 250 vfs_out_unmount(callid, &call); 251 break; 252 case VFS_OUT_LOOKUP: 253 vfs_out_lookup(callid, &call); 254 break; 255 case VFS_OUT_READ: 256 vfs_out_read(callid, &call); 257 break; 258 case VFS_OUT_WRITE: 259 vfs_out_write(callid, &call); 260 break; 261 case VFS_OUT_TRUNCATE: 262 vfs_out_truncate(callid, &call); 263 break; 264 case VFS_OUT_CLOSE: 265 vfs_out_close(callid, &call); 266 break; 267 case VFS_OUT_DESTROY: 268 vfs_out_destroy(callid, &call); 269 break; 270 case VFS_OUT_OPEN_NODE: 271 vfs_out_open_node(callid, &call); 272 break; 273 case VFS_OUT_STAT: 274 vfs_out_stat(callid, &call); 275 break; 276 case VFS_OUT_SYNC: 277 vfs_out_sync(callid, &call); 278 break; 279 default: 280 async_answer_0(callid, ENOTSUP); 281 break; 282 } 283 } 284 } 285 63 286 /** Register file system server. 64 287 * … … 67 290 * code. 68 291 * 69 * @param vfs_phone Open phone for communication with VFS. 70 * @param reg File system registration structure. It will be 71 * initialized by this function. 72 * @param info VFS info structure supplied by the file system 73 * implementation. 74 * @param conn Connection fibril for handling all calls originating in 75 * VFS. 292 * @param sess Session for communication with VFS. 293 * @param info VFS info structure supplied by the file system 294 * implementation. 295 * @param vops Address of the vfs_out_ops_t structure. 296 * @param lops Address of the libfs_ops_t structure. 76 297 * 77 298 * @return EOK on success or a non-zero error code on errror. 78 299 * 79 300 */ 80 int fs_register( int vfs_phone, fs_reg_t *reg, vfs_info_t *info,81 async_client_conn_t conn)301 int fs_register(async_sess_t *sess, vfs_info_t *info, vfs_out_ops_t *vops, 302 libfs_ops_t *lops) 82 303 { 83 304 /* … … 86 307 * out-of-order, when it knows that the operation succeeded or failed. 87 308 */ 309 310 async_exch_t *exch = async_exchange_begin(sess); 311 88 312 ipc_call_t answer; 89 aid_t req = async_send_0( vfs_phone, VFS_IN_REGISTER, &answer);313 aid_t req = async_send_0(exch, VFS_IN_REGISTER, &answer); 90 314 91 315 /* 92 316 * Send our VFS info structure to VFS. 93 317 */ 94 int rc = async_data_write_start(vfs_phone, info, sizeof(*info)); 318 int rc = async_data_write_start(exch, info, sizeof(*info)); 319 95 320 if (rc != EOK) { 321 async_exchange_end(exch); 96 322 async_wait_for(req, NULL); 97 323 return rc; … … 99 325 100 326 /* 327 * Set VFS_OUT and libfs operations. 328 */ 329 vfs_out_ops = vops; 330 libfs_ops = lops; 331 332 /* 101 333 * Ask VFS for callback connection. 102 334 */ 103 async_connect_to_me( vfs_phone, 0, 0, 0, conn);335 async_connect_to_me(exch, 0, 0, 0, vfs_connection, NULL); 104 336 105 337 /* 106 338 * Allocate piece of address space for PLB. 107 339 */ 108 reg->plb_ro = as_get_mappable_page(PLB_SIZE); 109 if (!reg->plb_ro) { 340 reg.plb_ro = as_get_mappable_page(PLB_SIZE); 341 if (!reg.plb_ro) { 342 async_exchange_end(exch); 110 343 async_wait_for(req, NULL); 111 344 return ENOMEM; … … 115 348 * Request sharing the Path Lookup Buffer with VFS. 116 349 */ 117 rc = async_share_in_start_0_0(vfs_phone, reg->plb_ro, PLB_SIZE); 350 rc = async_share_in_start_0_0(exch, reg.plb_ro, PLB_SIZE); 351 352 async_exchange_end(exch); 353 118 354 if (rc) { 119 355 async_wait_for(req, NULL); … … 125 361 */ 126 362 async_wait_for(req, NULL); 127 reg ->fs_handle = (int) IPC_GET_ARG1(answer);363 reg.fs_handle = (int) IPC_GET_ARG1(answer); 128 364 129 365 /* … … 131 367 * the same connection fibril as well. 132 368 */ 133 async_set_client_connection( conn);369 async_set_client_connection(vfs_connection); 134 370 135 371 return IPC_GET_RETVAL(answer); … … 142 378 143 379 void libfs_mount(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid, 144 ipc_call_t *request) 145 { 146 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 147 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request); 148 fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*request); 149 devmap_handle_t mr_devmap_handle = (devmap_handle_t) IPC_GET_ARG4(*request); 150 int res; 151 sysarg_t rc; 152 153 ipc_call_t call; 154 ipc_callid_t callid; 155 156 /* Accept the phone */ 157 callid = async_get_call(&call); 158 int mountee_phone = (int) IPC_GET_ARG1(call); 159 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECTION_CLONE) || 160 (mountee_phone < 0)) { 161 async_answer_0(callid, EINVAL); 380 ipc_call_t *req) 381 { 382 service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req); 383 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req); 384 fs_handle_t mr_fs_handle = (fs_handle_t) IPC_GET_ARG3(*req); 385 service_id_t mr_service_id = (service_id_t) IPC_GET_ARG4(*req); 386 387 async_sess_t *mountee_sess = async_clone_receive(EXCHANGE_PARALLEL); 388 if (mountee_sess == NULL) { 162 389 async_answer_0(rid, EINVAL); 163 390 return; 164 391 } 165 392 166 /* Acknowledge the mountee_phone */167 async_answer_0(callid, EOK);168 169 393 fs_node_t *fn; 170 res = ops->node_get(&fn, mp_devmap_handle, mp_fs_index);394 int res = ops->node_get(&fn, mp_service_id, mp_fs_index); 171 395 if ((res != EOK) || (!fn)) { 172 async_hangup(mountee_ phone);396 async_hangup(mountee_sess); 173 397 async_data_write_void(combine_rc(res, ENOENT)); 174 398 async_answer_0(rid, combine_rc(res, ENOENT)); … … 177 401 178 402 if (fn->mp_data.mp_active) { 179 async_hangup(mountee_ phone);403 async_hangup(mountee_sess); 180 404 (void) ops->node_put(fn); 181 405 async_data_write_void(EBUSY); … … 184 408 } 185 409 186 rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME); 187 if (rc != EOK) { 188 async_hangup(mountee_phone); 410 async_exch_t *exch = async_exchange_begin(mountee_sess); 411 async_sess_t *sess = async_connect_me(EXCHANGE_PARALLEL, exch); 412 413 if (!sess) { 414 async_exchange_end(exch); 415 async_hangup(mountee_sess); 189 416 (void) ops->node_put(fn); 190 async_data_write_void( rc);191 async_answer_0(rid, rc);417 async_data_write_void(errno); 418 async_answer_0(rid, errno); 192 419 return; 193 420 } 194 421 195 422 ipc_call_t answer; 196 rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED, 197 mr_devmap_handle, &answer); 423 int rc = async_data_write_forward_1_1(exch, VFS_OUT_MOUNTED, 424 mr_service_id, &answer); 425 async_exchange_end(exch); 198 426 199 427 if (rc == EOK) { 200 428 fn->mp_data.mp_active = true; 201 429 fn->mp_data.fs_handle = mr_fs_handle; 202 fn->mp_data. devmap_handle = mr_devmap_handle;203 fn->mp_data. phone = mountee_phone;430 fn->mp_data.service_id = mr_service_id; 431 fn->mp_data.sess = mountee_sess; 204 432 } 205 433 … … 207 435 * Do not release the FS node so that it stays in memory. 208 436 */ 209 async_answer_ 3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),210 IPC_GET_ARG3(answer) );211 } 212 213 void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *req uest)214 { 215 devmap_handle_t mp_devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);216 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req uest);437 async_answer_4(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 438 IPC_GET_ARG3(answer), IPC_GET_ARG4(answer)); 439 } 440 441 void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *req) 442 { 443 service_id_t mp_service_id = (service_id_t) IPC_GET_ARG1(*req); 444 fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*req); 217 445 fs_node_t *fn; 218 446 int res; 219 447 220 res = ops->node_get(&fn, mp_ devmap_handle, mp_fs_index);448 res = ops->node_get(&fn, mp_service_id, mp_fs_index); 221 449 if ((res != EOK) || (!fn)) { 222 450 async_answer_0(rid, combine_rc(res, ENOENT)); … … 236 464 * Tell the mounted file system to unmount. 237 465 */ 238 res = async_req_1_0(fn->mp_data.phone, VFS_OUT_UNMOUNTED, 239 fn->mp_data.devmap_handle); 466 async_exch_t *exch = async_exchange_begin(fn->mp_data.sess); 467 res = async_req_1_0(exch, VFS_OUT_UNMOUNTED, fn->mp_data.service_id); 468 async_exchange_end(exch); 240 469 241 470 /* … … 243 472 */ 244 473 if (res == EOK) { 245 async_hangup(fn->mp_data. phone);474 async_hangup(fn->mp_data.sess); 246 475 fn->mp_data.mp_active = false; 247 476 fn->mp_data.fs_handle = 0; 248 fn->mp_data.devmap_handle = 0; 249 fn->mp_data.phone = 0; 477 fn->mp_data.service_id = 0; 478 fn->mp_data.sess = NULL; 479 250 480 /* Drop the reference created in libfs_mount(). */ 251 481 (void) ops->node_put(fn); … … 254 484 (void) ops->node_put(fn); 255 485 async_answer_0(rid, res); 486 } 487 488 static char plb_get_char(unsigned pos) 489 { 490 return reg.plb_ro[pos % PLB_SIZE]; 256 491 } 257 492 … … 270 505 */ 271 506 void libfs_lookup(libfs_ops_t *ops, fs_handle_t fs_handle, ipc_callid_t rid, 272 ipc_call_t *req uest)273 { 274 unsigned int first = IPC_GET_ARG1(*req uest);275 unsigned int last = IPC_GET_ARG2(*req uest);507 ipc_call_t *req) 508 { 509 unsigned int first = IPC_GET_ARG1(*req); 510 unsigned int last = IPC_GET_ARG2(*req); 276 511 unsigned int next = first; 277 devmap_handle_t devmap_handle = IPC_GET_ARG3(*request);278 int lflag = IPC_GET_ARG4(*req uest);279 fs_index_t index = IPC_GET_ARG5(*req uest);512 service_id_t service_id = IPC_GET_ARG3(*req); 513 int lflag = IPC_GET_ARG4(*req); 514 fs_index_t index = IPC_GET_ARG5(*req); 280 515 char component[NAME_MAX + 1]; 281 516 int len; … … 289 524 fs_node_t *tmp = NULL; 290 525 291 rc = ops->root_get(&cur, devmap_handle);526 rc = ops->root_get(&cur, service_id); 292 527 on_error(rc, goto out_with_answer); 293 528 294 529 if (cur->mp_data.mp_active) { 295 async_forward_slow(rid, cur->mp_data.phone, VFS_OUT_LOOKUP, 296 next, last, cur->mp_data.devmap_handle, lflag, index, 530 async_exch_t *exch = async_exchange_begin(cur->mp_data.sess); 531 async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, last, 532 cur->mp_data.service_id, lflag, index, 297 533 IPC_FF_ROUTE_FROM_ME); 534 async_exchange_end(exch); 535 298 536 (void) ops->node_put(cur); 299 537 return; … … 301 539 302 540 /* Eat slash */ 303 if ( ops->plb_get_char(next) == '/')541 if (plb_get_char(next) == '/') 304 542 next++; 305 543 … … 314 552 /* Collect the component */ 315 553 len = 0; 316 while ((next <= last) && ( ops->plb_get_char(next) != '/')) {554 while ((next <= last) && (plb_get_char(next) != '/')) { 317 555 if (len + 1 == NAME_MAX) { 318 556 /* Component length overflow */ … … 320 558 goto out; 321 559 } 322 component[len++] = ops->plb_get_char(next);560 component[len++] = plb_get_char(next); 323 561 /* Process next character */ 324 562 next++; … … 351 589 next--; 352 590 353 async_forward_slow(rid, tmp->mp_data.phone, 354 VFS_OUT_LOOKUP, next, last, tmp->mp_data.devmap_handle, 355 lflag, index, IPC_FF_ROUTE_FROM_ME); 591 async_exch_t *exch = async_exchange_begin(tmp->mp_data.sess); 592 async_forward_slow(rid, exch, VFS_OUT_LOOKUP, next, 593 last, tmp->mp_data.service_id, lflag, index, 594 IPC_FF_ROUTE_FROM_ME); 595 async_exchange_end(exch); 596 356 597 (void) ops->node_put(cur); 357 598 (void) ops->node_put(tmp); … … 379 620 fs_node_t *fn; 380 621 if (lflag & L_CREATE) 381 rc = ops->create(&fn, devmap_handle,622 rc = ops->create(&fn, service_id, 382 623 lflag); 383 624 else 384 rc = ops->node_get(&fn, devmap_handle,625 rc = ops->node_get(&fn, service_id, 385 626 index); 386 627 on_error(rc, goto out_with_answer); … … 397 638 aoff64_t size = ops->size_get(fn); 398 639 async_answer_5(rid, fs_handle, 399 devmap_handle,640 service_id, 400 641 ops->index_get(fn), 401 642 LOWER32(size), … … 443 684 len = 0; 444 685 while (next <= last) { 445 if ( ops->plb_get_char(next) == '/') {686 if (plb_get_char(next) == '/') { 446 687 /* More than one component */ 447 688 async_answer_0(rid, ENOENT); … … 455 696 } 456 697 457 component[len++] = ops->plb_get_char(next);698 component[len++] = plb_get_char(next); 458 699 /* Process next character */ 459 700 next++; … … 465 706 fs_node_t *fn; 466 707 if (lflag & L_CREATE) 467 rc = ops->create(&fn, devmap_handle, lflag);708 rc = ops->create(&fn, service_id, lflag); 468 709 else 469 rc = ops->node_get(&fn, devmap_handle, index);710 rc = ops->node_get(&fn, service_id, index); 470 711 on_error(rc, goto out_with_answer); 471 712 … … 481 722 aoff64_t size = ops->size_get(fn); 482 723 async_answer_5(rid, fs_handle, 483 devmap_handle,724 service_id, 484 725 ops->index_get(fn), 485 726 LOWER32(size), … … 507 748 if (rc == EOK) { 508 749 aoff64_t size = ops->size_get(cur); 509 async_answer_5(rid, fs_handle, devmap_handle,750 async_answer_5(rid, fs_handle, service_id, 510 751 ops->index_get(cur), LOWER32(size), UPPER32(size), 511 752 old_lnkcnt); … … 545 786 if (rc == EOK) { 546 787 aoff64_t size = ops->size_get(cur); 547 async_answer_5(rid, fs_handle, devmap_handle,788 async_answer_5(rid, fs_handle, service_id, 548 789 ops->index_get(cur), LOWER32(size), UPPER32(size), 549 790 ops->lnkcnt_get(cur)); … … 569 810 ipc_call_t *request) 570 811 { 571 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);812 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 572 813 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 573 814 574 815 fs_node_t *fn; 575 int rc = ops->node_get(&fn, devmap_handle, index);816 int rc = ops->node_get(&fn, service_id, index); 576 817 on_error(rc, answer_and_return(rid, rc)); 577 818 … … 590 831 591 832 stat.fs_handle = fs_handle; 592 stat. devmap_handle = devmap_handle;833 stat.service_id = service_id; 593 834 stat.index = index; 594 835 stat.lnkcnt = ops->lnkcnt_get(fn); … … 596 837 stat.is_directory = ops->is_directory(fn); 597 838 stat.size = ops->size_get(fn); 598 stat. device = ops->device_get(fn);839 stat.service = ops->service_get(fn); 599 840 600 841 ops->node_put(fn); … … 615 856 ipc_call_t *request) 616 857 { 617 devmap_handle_t devmap_handle= IPC_GET_ARG1(*request);858 service_id_t service_id = IPC_GET_ARG1(*request); 618 859 fs_index_t index = IPC_GET_ARG2(*request); 619 860 620 861 fs_node_t *fn; 621 int rc = ops->node_get(&fn, devmap_handle, index);862 int rc = ops->node_get(&fn, service_id, index); 622 863 on_error(rc, answer_and_return(rid, rc)); 623 864 … … 629 870 rc = ops->node_open(fn); 630 871 aoff64_t size = ops->size_get(fn); 631 async_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn), 872 async_answer_4(rid, rc, LOWER32(size), UPPER32(size), 873 ops->lnkcnt_get(fn), 632 874 (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0)); 633 875 634 876 (void) ops->node_put(fn); 877 } 878 879 static FIBRIL_MUTEX_INITIALIZE(instances_mutex); 880 static LIST_INITIALIZE(instances_list); 881 882 typedef struct { 883 service_id_t service_id; 884 link_t link; 885 void *data; 886 } fs_instance_t; 887 888 int fs_instance_create(service_id_t service_id, void *data) 889 { 890 fs_instance_t *inst = malloc(sizeof(fs_instance_t)); 891 if (!inst) 892 return ENOMEM; 893 894 link_initialize(&inst->link); 895 inst->service_id = service_id; 896 inst->data = data; 897 898 fibril_mutex_lock(&instances_mutex); 899 list_foreach(instances_list, link) { 900 fs_instance_t *cur = list_get_instance(link, fs_instance_t, 901 link); 902 903 if (cur->service_id == service_id) { 904 fibril_mutex_unlock(&instances_mutex); 905 free(inst); 906 return EEXIST; 907 } 908 909 /* keep the list sorted */ 910 if (cur->service_id < service_id) { 911 list_insert_before(&inst->link, &cur->link); 912 fibril_mutex_unlock(&instances_mutex); 913 return EOK; 914 } 915 } 916 list_append(&inst->link, &instances_list); 917 fibril_mutex_unlock(&instances_mutex); 918 919 return EOK; 920 } 921 922 int fs_instance_get(service_id_t service_id, void **idp) 923 { 924 fibril_mutex_lock(&instances_mutex); 925 list_foreach(instances_list, link) { 926 fs_instance_t *inst = list_get_instance(link, fs_instance_t, 927 link); 928 929 if (inst->service_id == service_id) { 930 *idp = inst->data; 931 fibril_mutex_unlock(&instances_mutex); 932 return EOK; 933 } 934 } 935 fibril_mutex_unlock(&instances_mutex); 936 return ENOENT; 937 } 938 939 int fs_instance_destroy(service_id_t service_id) 940 { 941 fibril_mutex_lock(&instances_mutex); 942 list_foreach(instances_list, link) { 943 fs_instance_t *inst = list_get_instance(link, fs_instance_t, 944 link); 945 946 if (inst->service_id == service_id) { 947 list_remove(&inst->link); 948 fibril_mutex_unlock(&instances_mutex); 949 free(inst); 950 return EOK; 951 } 952 } 953 fibril_mutex_unlock(&instances_mutex); 954 return ENOENT; 635 955 } 636 956
Note:
See TracChangeset
for help on using the changeset viewer.