Changes in uspace/lib/libfs/libfs.c [0daba212:0143f72] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
r0daba212 r0143f72 46 46 #include <sys/stat.h> 47 47 48 #define on_error(rc, action) \49 do { \50 if ((rc) != EOK) \51 action; \52 } while (0)53 54 #define combine_rc(rc1, rc2) \55 ((rc1) == EOK ? (rc2) : (rc1))56 57 #define answer_and_return(rid, rc) \58 do { \59 ipc_answer_0((rid), (rc)); \60 return; \61 } while (0)62 63 48 /** Register file system server. 64 49 * … … 177 162 } 178 163 179 fs_node_t *fn; 180 res = ops->node_get(&fn, mp_dev_handle, mp_fs_index); 181 if (res != EOK || !fn) { 164 fs_node_t *fn = ops->node_get(mp_dev_handle, mp_fs_index); 165 if (!fn) { 182 166 ipc_hangup(mountee_phone); 183 ipc_answer_0(callid, combine_rc(res, ENOENT));184 ipc_answer_0(rid, combine_rc(res, ENOENT));167 ipc_answer_0(callid, ENOENT); 168 ipc_answer_0(rid, ENOENT); 185 169 return; 186 170 } … … 188 172 if (fn->mp_data.mp_active) { 189 173 ipc_hangup(mountee_phone); 190 (void)ops->node_put(fn);174 ops->node_put(fn); 191 175 ipc_answer_0(callid, EBUSY); 192 176 ipc_answer_0(rid, EBUSY); … … 195 179 196 180 rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME); 197 if (rc != EOK) {181 if (rc != 0) { 198 182 ipc_hangup(mountee_phone); 199 (void)ops->node_put(fn);183 ops->node_put(fn); 200 184 ipc_answer_0(callid, rc); 201 185 ipc_answer_0(rid, rc); … … 246 230 char component[NAME_MAX + 1]; 247 231 int len; 248 int rc;249 232 250 233 if (last < next) … … 252 235 253 236 fs_node_t *par = NULL; 254 fs_node_t *cur = NULL;237 fs_node_t *cur = ops->root_get(dev_handle); 255 238 fs_node_t *tmp = NULL; 256 257 rc = ops->root_get(&cur, dev_handle);258 on_error(rc, goto out_with_answer);259 239 260 240 if (cur->mp_data.mp_active) { … … 262 242 next, last, cur->mp_data.dev_handle, lflag, index, 263 243 IPC_FF_ROUTE_FROM_ME); 264 (void)ops->node_put(cur);244 ops->node_put(cur); 265 245 return; 266 246 } … … 269 249 next++; /* eat slash */ 270 250 271 while (next <= last) { 272 bool has_children; 273 274 rc = ops->has_children(&has_children, cur); 275 on_error(rc, goto out_with_answer); 276 if (!has_children) 277 break; 278 251 while (next <= last && ops->has_children(cur)) { 279 252 /* collect the component */ 280 253 len = 0; … … 294 267 295 268 /* match the component */ 296 rc = ops->match(&tmp, cur, component); 297 on_error(rc, goto out_with_answer); 298 269 tmp = ops->match(cur, component); 299 270 if (tmp && tmp->mp_data.mp_active) { 300 271 if (next > last) … … 306 277 VFS_OUT_LOOKUP, next, last, tmp->mp_data.dev_handle, 307 278 lflag, index, IPC_FF_ROUTE_FROM_ME); 308 (void)ops->node_put(cur);309 (void)ops->node_put(tmp);279 ops->node_put(cur); 280 ops->node_put(tmp); 310 281 if (par) 311 (void)ops->node_put(par);282 ops->node_put(par); 312 283 return; 313 284 } … … 329 300 fs_node_t *fn; 330 301 if (lflag & L_CREATE) 331 rc = ops->create(&fn, dev_handle, 332 lflag); 302 fn = ops->create(dev_handle, lflag); 333 303 else 334 rc = ops->node_get(&fn,dev_handle,304 fn = ops->node_get(dev_handle, 335 305 index); 336 on_error(rc, goto out_with_answer);337 306 if (fn) { 307 int rc; 308 338 309 rc = ops->link(cur, fn, component); 339 310 if (rc != EOK) { 340 if (lflag & L_CREATE) 341 (void) ops->destroy(fn); 311 if (lflag & L_CREATE) { 312 (void)ops->destroy(fn); 313 } 342 314 ipc_answer_0(rid, rc); 343 315 } else { … … 347 319 ops->size_get(fn), 348 320 ops->lnkcnt_get(fn)); 349 (void)ops->node_put(fn);321 ops->node_put(fn); 350 322 } 351 323 } else { … … 358 330 } 359 331 360 if (par) { 361 rc = ops->node_put(par); 362 on_error(rc, goto out_with_answer); 363 } 332 if (par) 333 ops->node_put(par); 364 334 365 335 /* descend one level */ … … 370 340 371 341 /* handle miss: excessive components */ 372 if (next <= last) { 373 bool has_children; 374 375 rc = ops->has_children(&has_children, cur); 376 on_error(rc, goto out_with_answer); 377 if (has_children) 378 goto skip_miss; 379 342 if (next <= last && !ops->has_children(cur)) { 380 343 if (lflag & (L_CREATE | L_LINK)) { 381 344 if (!ops->is_directory(cur)) { … … 405 368 fs_node_t *fn; 406 369 if (lflag & L_CREATE) 407 rc = ops->create(&fn,dev_handle, lflag);370 fn = ops->create(dev_handle, lflag); 408 371 else 409 rc = ops->node_get(&fn, dev_handle, index); 410 on_error(rc, goto out_with_answer); 372 fn = ops->node_get(dev_handle, index); 411 373 if (fn) { 374 int rc; 375 412 376 rc = ops->link(cur, fn, component); 413 377 if (rc != EOK) { 414 378 if (lflag & L_CREATE) 415 (void) 379 (void)ops->destroy(fn); 416 380 ipc_answer_0(rid, rc); 417 381 } else { … … 421 385 ops->size_get(fn), 422 386 ops->lnkcnt_get(fn)); 423 (void)ops->node_put(fn);387 ops->node_put(fn); 424 388 } 425 389 } else { … … 431 395 goto out; 432 396 } 433 skip_miss:434 397 435 398 /* handle hit */ 436 399 if (lflag & L_UNLINK) { 437 400 unsigned old_lnkcnt = ops->lnkcnt_get(cur); 438 rc= ops->unlink(par, cur, component);439 ipc_answer_5(rid, (ipcarg_t)r c, fs_handle, dev_handle,401 int res = ops->unlink(par, cur, component); 402 ipc_answer_5(rid, (ipcarg_t)res, fs_handle, dev_handle, 440 403 ops->index_get(cur), ops->size_get(cur), old_lnkcnt); 441 404 goto out; … … 455 418 } 456 419 457 out_with_answer: 458 if (rc == EOK) { 459 ipc_answer_5(rid, EOK, fs_handle, dev_handle, 460 ops->index_get(cur), ops->size_get(cur), 461 ops->lnkcnt_get(cur)); 462 } else { 463 ipc_answer_0(rid, rc); 464 } 420 ipc_answer_5(rid, EOK, fs_handle, dev_handle, ops->index_get(cur), 421 ops->size_get(cur), ops->lnkcnt_get(cur)); 465 422 466 423 out: 467 424 if (par) 468 (void)ops->node_put(par);425 ops->node_put(par); 469 426 if (cur) 470 (void)ops->node_put(cur);427 ops->node_put(cur); 471 428 if (tmp) 472 (void)ops->node_put(tmp);429 ops->node_put(tmp); 473 430 } 474 431 … … 478 435 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 479 436 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 480 fs_node_t *fn; 481 int rc; 482 483 rc = ops->node_get(&fn, dev_handle, index); 484 on_error(rc, answer_and_return(rid, rc)); 437 fs_node_t *fn = ops->node_get(dev_handle, index); 485 438 486 439 ipc_callid_t callid; … … 520 473 dev_handle_t dev_handle = IPC_GET_ARG1(*request); 521 474 fs_index_t index = IPC_GET_ARG2(*request); 522 fs_node_t *fn; 523 int rc; 524 525 rc = ops->node_get(&fn, dev_handle, index); 526 on_error(rc, answer_and_return(rid, rc)); 527 528 if (fn == NULL) { 475 476 fs_node_t *node = ops->node_get(dev_handle, index); 477 478 if (node == NULL) { 529 479 ipc_answer_0(rid, ENOENT); 530 480 return; 531 481 } 532 482 533 ipc_answer_5(rid, EOK, fs_handle, dev_handle, index, ops->size_get(fn),534 ops-> lnkcnt_get(fn));535 536 (void) ops->node_put(fn);483 ipc_answer_5(rid, EOK, fs_handle, dev_handle, index, 484 ops->size_get(node), ops->lnkcnt_get(node)); 485 486 ops->node_put(node); 537 487 } 538 488
Note:
See TracChangeset
for help on using the changeset viewer.