Changeset 0daba21 in mainline
- Timestamp:
- 2009-09-24T15:56:54Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54e4479
- Parents:
- edb14ca
- Location:
- uspace/lib/libfs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
redb14ca r0daba21 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 48 63 /** Register file system server. 49 64 * … … 162 177 } 163 178 164 fs_node_t *fn = ops->node_get(mp_dev_handle, mp_fs_index); 165 if (!fn) { 179 fs_node_t *fn; 180 res = ops->node_get(&fn, mp_dev_handle, mp_fs_index); 181 if (res != EOK || !fn) { 166 182 ipc_hangup(mountee_phone); 167 ipc_answer_0(callid, ENOENT);168 ipc_answer_0(rid, ENOENT);183 ipc_answer_0(callid, combine_rc(res, ENOENT)); 184 ipc_answer_0(rid, combine_rc(res, ENOENT)); 169 185 return; 170 186 } … … 172 188 if (fn->mp_data.mp_active) { 173 189 ipc_hangup(mountee_phone); 174 ops->node_put(fn);190 (void) ops->node_put(fn); 175 191 ipc_answer_0(callid, EBUSY); 176 192 ipc_answer_0(rid, EBUSY); … … 179 195 180 196 rc = async_req_0_0(mountee_phone, IPC_M_CONNECT_ME); 181 if (rc != 0) {197 if (rc != EOK) { 182 198 ipc_hangup(mountee_phone); 183 ops->node_put(fn);199 (void) ops->node_put(fn); 184 200 ipc_answer_0(callid, rc); 185 201 ipc_answer_0(rid, rc); … … 230 246 char component[NAME_MAX + 1]; 231 247 int len; 248 int rc; 232 249 233 250 if (last < next) … … 235 252 236 253 fs_node_t *par = NULL; 237 fs_node_t *cur = ops->root_get(dev_handle);254 fs_node_t *cur = NULL; 238 255 fs_node_t *tmp = NULL; 256 257 rc = ops->root_get(&cur, dev_handle); 258 on_error(rc, goto out_with_answer); 239 259 240 260 if (cur->mp_data.mp_active) { … … 242 262 next, last, cur->mp_data.dev_handle, lflag, index, 243 263 IPC_FF_ROUTE_FROM_ME); 244 ops->node_put(cur);264 (void) ops->node_put(cur); 245 265 return; 246 266 } … … 249 269 next++; /* eat slash */ 250 270 251 while (next <= last && ops->has_children(cur)) { 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 252 279 /* collect the component */ 253 280 len = 0; … … 267 294 268 295 /* match the component */ 269 tmp = ops->match(cur, component); 296 rc = ops->match(&tmp, cur, component); 297 on_error(rc, goto out_with_answer); 298 270 299 if (tmp && tmp->mp_data.mp_active) { 271 300 if (next > last) … … 277 306 VFS_OUT_LOOKUP, next, last, tmp->mp_data.dev_handle, 278 307 lflag, index, IPC_FF_ROUTE_FROM_ME); 279 ops->node_put(cur);280 ops->node_put(tmp);308 (void) ops->node_put(cur); 309 (void) ops->node_put(tmp); 281 310 if (par) 282 ops->node_put(par);311 (void) ops->node_put(par); 283 312 return; 284 313 } … … 300 329 fs_node_t *fn; 301 330 if (lflag & L_CREATE) 302 fn = ops->create(dev_handle, lflag); 331 rc = ops->create(&fn, dev_handle, 332 lflag); 303 333 else 304 fn = ops->node_get(dev_handle,334 rc = ops->node_get(&fn, dev_handle, 305 335 index); 336 on_error(rc, goto out_with_answer); 306 337 if (fn) { 307 int rc;308 309 338 rc = ops->link(cur, fn, component); 310 339 if (rc != EOK) { 311 if (lflag & L_CREATE) { 312 (void)ops->destroy(fn); 313 } 340 if (lflag & L_CREATE) 341 (void) ops->destroy(fn); 314 342 ipc_answer_0(rid, rc); 315 343 } else { … … 319 347 ops->size_get(fn), 320 348 ops->lnkcnt_get(fn)); 321 ops->node_put(fn);349 (void) ops->node_put(fn); 322 350 } 323 351 } else { … … 330 358 } 331 359 332 if (par) 333 ops->node_put(par); 360 if (par) { 361 rc = ops->node_put(par); 362 on_error(rc, goto out_with_answer); 363 } 334 364 335 365 /* descend one level */ … … 340 370 341 371 /* handle miss: excessive components */ 342 if (next <= last && !ops->has_children(cur)) { 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 343 380 if (lflag & (L_CREATE | L_LINK)) { 344 381 if (!ops->is_directory(cur)) { … … 368 405 fs_node_t *fn; 369 406 if (lflag & L_CREATE) 370 fn = ops->create(dev_handle, lflag);407 rc = ops->create(&fn, dev_handle, lflag); 371 408 else 372 fn = ops->node_get(dev_handle, index); 409 rc = ops->node_get(&fn, dev_handle, index); 410 on_error(rc, goto out_with_answer); 373 411 if (fn) { 374 int rc;375 376 412 rc = ops->link(cur, fn, component); 377 413 if (rc != EOK) { 378 414 if (lflag & L_CREATE) 379 (void) ops->destroy(fn);415 (void) ops->destroy(fn); 380 416 ipc_answer_0(rid, rc); 381 417 } else { … … 385 421 ops->size_get(fn), 386 422 ops->lnkcnt_get(fn)); 387 ops->node_put(fn);423 (void) ops->node_put(fn); 388 424 } 389 425 } else { … … 395 431 goto out; 396 432 } 433 skip_miss: 397 434 398 435 /* handle hit */ 399 436 if (lflag & L_UNLINK) { 400 437 unsigned old_lnkcnt = ops->lnkcnt_get(cur); 401 int res= ops->unlink(par, cur, component);402 ipc_answer_5(rid, (ipcarg_t)r es, fs_handle, dev_handle,438 rc = ops->unlink(par, cur, component); 439 ipc_answer_5(rid, (ipcarg_t)rc, fs_handle, dev_handle, 403 440 ops->index_get(cur), ops->size_get(cur), old_lnkcnt); 404 441 goto out; … … 418 455 } 419 456 420 ipc_answer_5(rid, EOK, fs_handle, dev_handle, ops->index_get(cur), 421 ops->size_get(cur), ops->lnkcnt_get(cur)); 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 } 422 465 423 466 out: 424 467 if (par) 425 ops->node_put(par);468 (void) ops->node_put(par); 426 469 if (cur) 427 ops->node_put(cur);470 (void) ops->node_put(cur); 428 471 if (tmp) 429 ops->node_put(tmp);472 (void) ops->node_put(tmp); 430 473 } 431 474 … … 435 478 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 436 479 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 437 fs_node_t *fn = ops->node_get(dev_handle, index); 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)); 438 485 439 486 ipc_callid_t callid; … … 473 520 dev_handle_t dev_handle = IPC_GET_ARG1(*request); 474 521 fs_index_t index = IPC_GET_ARG2(*request); 475 476 fs_node_t *node = ops->node_get(dev_handle, index); 477 478 if (node == NULL) { 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) { 479 529 ipc_answer_0(rid, ENOENT); 480 530 return; 481 531 } 482 532 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);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); 487 537 } 488 538 -
uspace/lib/libfs/libfs.h
redb14ca r0daba21 56 56 57 57 typedef struct { 58 fs_node_t * (* match)(fs_node_t *, const char *); 59 fs_node_t * (* node_get)(dev_handle_t, fs_index_t); 60 void (* node_put)(fs_node_t *); 61 fs_node_t * (* create)(dev_handle_t, int); 58 /* 59 * The first set of methods are functions that return an integer error 60 * code. If some additional return value is to be returned, the first 61 * argument holds the output argument. 62 */ 63 int (* root_get)(fs_node_t **, dev_handle_t); 64 int (* match)(fs_node_t **, fs_node_t *, const char *); 65 int (* node_get)(fs_node_t **, dev_handle_t, fs_index_t); 66 int (* node_put)(fs_node_t *); 67 int (* create)(fs_node_t **, dev_handle_t, int); 62 68 int (* destroy)(fs_node_t *); 63 69 int (* link)(fs_node_t *, fs_node_t *, const char *); 64 70 int (* unlink)(fs_node_t *, fs_node_t *, const char *); 71 int (* has_children)(bool *, fs_node_t *); 72 /* 73 * The second set of methods are usually mere getters that do not return 74 * an integer error code. 75 */ 65 76 fs_index_t (* index_get)(fs_node_t *); 66 77 size_t (* size_get)(fs_node_t *); 67 78 unsigned (* lnkcnt_get)(fs_node_t *); 68 bool (* has_children)(fs_node_t *);69 fs_node_t *(* root_get)(dev_handle_t);70 79 char (* plb_get_char)(unsigned pos); 71 80 bool (* is_directory)(fs_node_t *);
Note:
See TracChangeset
for help on using the changeset viewer.