Changeset 7858bc5f in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2008-10-28T15:40:19Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 916bf1a
- Parents:
- 5cf723b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
r5cf723b r7858bc5f 76 76 static void fat_node_sync(fat_node_t *node) 77 77 { 78 block_t *bb, *b; 78 block_t *b; 79 fat_bs_t *bs; 79 80 fat_dentry_t *d; 80 81 uint16_t bps; … … 83 84 assert(node->dirty); 84 85 85 b b = block_get(node->idx->dev_handle, BS_BLOCK, BS_SIZE);86 bps = uint16_t_le2host( FAT_BS(bb)->bps);86 bs = block_bb_get(node->idx->dev_handle); 87 bps = uint16_t_le2host(bs->bps); 87 88 dps = bps / sizeof(fat_dentry_t); 88 89 89 90 /* Read the block that contains the dentry of interest. */ 90 b = _fat_block_get(b b->data, node->idx->dev_handle, node->idx->pfc,91 b = _fat_block_get(bs, node->idx->dev_handle, node->idx->pfc, 91 92 (node->idx->pdi * sizeof(fat_dentry_t)) / bps); 92 93 … … 100 101 b->dirty = true; /* need to sync block */ 101 102 block_put(b); 102 block_put(bb);103 103 } 104 104 … … 109 109 static void *fat_node_get_core(fat_idx_t *idxp) 110 110 { 111 block_t *bb, *b; 111 block_t *b; 112 fat_bs_t *bs; 112 113 fat_dentry_t *d; 113 114 fat_node_t *nodep = NULL; … … 162 163 fat_node_initialize(nodep); 163 164 164 b b = block_get(idxp->dev_handle, BS_BLOCK, BS_SIZE);165 bps = uint16_t_le2host( FAT_BS(bb)->bps);165 bs = block_bb_get(idxp->dev_handle); 166 bps = uint16_t_le2host(bs->bps); 166 167 dps = bps / sizeof(fat_dentry_t); 167 168 168 169 /* Read the block that contains the dentry of interest. */ 169 b = _fat_block_get(b b->data, idxp->dev_handle, idxp->pfc,170 b = _fat_block_get(bs, idxp->dev_handle, idxp->pfc, 170 171 (idxp->pdi * sizeof(fat_dentry_t)) / bps); 171 172 assert(b); … … 184 185 * size of the directory by walking the FAT. 185 186 */ 186 nodep->size = bps * _fat_blcks_get(b b->data, idxp->dev_handle,187 nodep->size = bps * _fat_blcks_get(bs, idxp->dev_handle, 187 188 uint16_t_le2host(d->firstc), NULL); 188 189 } else { … … 195 196 196 197 block_put(b); 197 block_put(bb);198 198 199 199 /* Link the idx structure with the node structure. */ … … 254 254 static void *fat_match(void *prnt, const char *component) 255 255 { 256 fat_bs_t *bs; 256 257 fat_node_t *parentp = (fat_node_t *)prnt; 257 258 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; … … 261 262 unsigned blocks; 262 263 fat_dentry_t *d; 263 block_t *b b, *b;264 block_t *b; 264 265 265 266 futex_down(&parentp->idx->lock); 266 b b = block_get(parentp->idx->dev_handle, BS_BLOCK, BS_SIZE);267 bps = uint16_t_le2host( FAT_BS(bb)->bps);267 bs = block_bb_get(parentp->idx->dev_handle); 268 bps = uint16_t_le2host(bs->bps); 268 269 dps = bps / sizeof(fat_dentry_t); 269 270 blocks = parentp->size / bps; 270 271 for (i = 0; i < blocks; i++) { 271 b = fat_block_get(b b->data, parentp, i);272 b = fat_block_get(bs, parentp, i); 272 273 for (j = 0; j < dps; j++) { 273 274 d = ((fat_dentry_t *)b->data) + j; … … 277 278 case FAT_DENTRY_LAST: 278 279 block_put(b); 279 block_put(bb);280 280 futex_up(&parentp->idx->lock); 281 281 return NULL; … … 304 304 */ 305 305 block_put(b); 306 block_put(bb);307 306 return NULL; 308 307 } … … 310 309 futex_up(&idx->lock); 311 310 block_put(b); 312 block_put(bb);313 311 return node; 314 312 } … … 316 314 block_put(b); 317 315 } 318 block_put(bb);319 316 320 317 futex_up(&parentp->idx->lock); … … 342 339 static bool fat_has_children(void *node) 343 340 { 341 fat_bs_t *bs; 344 342 fat_node_t *nodep = (fat_node_t *)node; 345 343 unsigned bps; 346 344 unsigned dps; 347 345 unsigned blocks; 348 block_t *b b, *b;346 block_t *b; 349 347 unsigned i, j; 350 348 … … 353 351 354 352 futex_down(&nodep->idx->lock); 355 b b = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE);356 bps = uint16_t_le2host( FAT_BS(bb)->bps);353 bs = block_bb_get(nodep->idx->dev_handle); 354 bps = uint16_t_le2host(bs->bps); 357 355 dps = bps / sizeof(fat_dentry_t); 358 356 … … 362 360 fat_dentry_t *d; 363 361 364 b = fat_block_get(b b->data, nodep, i);362 b = fat_block_get(bs, nodep, i); 365 363 for (j = 0; j < dps; j++) { 366 364 d = ((fat_dentry_t *)b->data) + j; … … 370 368 case FAT_DENTRY_LAST: 371 369 block_put(b); 372 block_put(bb);373 370 futex_up(&nodep->idx->lock); 374 371 return false; … … 376 373 case FAT_DENTRY_VALID: 377 374 block_put(b); 378 block_put(bb);379 375 futex_up(&nodep->idx->lock); 380 376 return true; 381 377 } 382 378 block_put(b); 383 block_put(bb);384 379 futex_up(&nodep->idx->lock); 385 380 return true; … … 387 382 block_put(b); 388 383 } 389 block_put(bb);390 384 391 385 futex_up(&nodep->idx->lock); … … 435 429 { 436 430 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 437 block_t *bb;431 fat_bs_t *bs; 438 432 uint16_t bps; 439 433 uint16_t rde; 440 434 int rc; 441 435 442 /* 443 * For now, we don't bother to remember dev_handle, dev_phone or 444 * dev_buffer in some data structure. We use global variables because we 445 * know there will be at most one mount on this file system. 446 * Of course, this is a huge TODO item. 447 */ 448 dev_buffer = mmap(NULL, BS_SIZE, PROTO_READ | PROTO_WRITE, 449 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 450 451 if (!dev_buffer) { 452 ipc_answer_0(rid, ENOMEM); 453 return; 454 } 455 456 dev_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 457 DEVMAP_CONNECT_TO_DEVICE, dev_handle); 458 459 if (dev_phone < 0) { 460 munmap(dev_buffer, BS_SIZE); 461 ipc_answer_0(rid, dev_phone); 462 return; 463 } 464 465 rc = ipc_share_out_start(dev_phone, dev_buffer, 466 AS_AREA_READ | AS_AREA_WRITE); 436 /* initialize libblock */ 437 rc = block_init(dev_handle, BS_SIZE, BS_BLOCK * BS_SIZE, BS_SIZE); 467 438 if (rc != EOK) { 468 munmap(dev_buffer, BS_SIZE); 469 ipc_answer_0(rid, rc); 470 return; 471 } 472 439 ipc_answer_0(rid, 0); 440 return; 441 } 442 443 /* get the buffer with the boot sector */ 444 bs = block_bb_get(dev_handle); 445 473 446 /* Read the number of root directory entries. */ 474 bb = block_get(dev_handle, BS_BLOCK, BS_SIZE); 475 bps = uint16_t_le2host(FAT_BS(bb)->bps); 476 rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max); 477 block_put(bb); 447 bps = uint16_t_le2host(bs->bps); 448 rde = uint16_t_le2host(bs->root_ent_max); 478 449 479 450 if (bps != BS_SIZE) { 480 munmap(dev_buffer, BS_SIZE);451 block_fini(dev_handle); 481 452 ipc_answer_0(rid, ENOTSUP); 482 453 return; … … 485 456 rc = fat_idx_init_by_dev_handle(dev_handle); 486 457 if (rc != EOK) { 487 munmap(dev_buffer, BS_SIZE);458 block_fini(dev_handle); 488 459 ipc_answer_0(rid, rc); 489 460 return; … … 493 464 fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t)); 494 465 if (!rootp) { 495 munmap(dev_buffer, BS_SIZE);466 block_fini(dev_handle); 496 467 fat_idx_fini_by_dev_handle(dev_handle); 497 468 ipc_answer_0(rid, ENOMEM); … … 502 473 fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0); 503 474 if (!ridxp) { 504 munmap(dev_buffer, BS_SIZE);475 block_fini(dev_handle); 505 476 free(rootp); 506 477 fat_idx_fini_by_dev_handle(dev_handle); … … 540 511 off_t pos = (off_t)IPC_GET_ARG3(*request); 541 512 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 513 fat_bs_t *bs; 542 514 uint16_t bps; 543 515 size_t bytes; 544 block_t *b b, *b;516 block_t *b; 545 517 546 518 if (!nodep) { … … 558 530 } 559 531 560 b b = block_get(dev_handle, BS_BLOCK, BS_SIZE);561 bps = uint16_t_le2host( FAT_BS(bb)->bps);532 bs = block_bb_get(dev_handle); 533 bps = uint16_t_le2host(bs->bps); 562 534 563 535 if (nodep->type == FAT_FILE) { … … 568 540 */ 569 541 bytes = min(len, bps - pos % bps); 570 b = fat_block_get(b b->data, nodep, pos / bps);542 b = fat_block_get(bs, nodep, pos / bps); 571 543 (void) ipc_data_read_finalize(callid, b->data + pos % bps, 572 544 bytes); … … 592 564 off_t o; 593 565 594 b = fat_block_get(b b->data, nodep, bnum);566 b = fat_block_get(bs, nodep, bnum); 595 567 for (o = pos % (bps / sizeof(fat_dentry_t)); 596 568 o < bps / sizeof(fat_dentry_t); … … 615 587 miss: 616 588 fat_node_put(nodep); 617 block_put(bb);618 589 ipc_answer_0(callid, ENOENT); 619 590 ipc_answer_1(rid, ENOENT, 0); … … 625 596 626 597 fat_node_put(nodep); 627 block_put(bb);628 598 ipc_answer_1(rid, EOK, (ipcarg_t)bytes); 629 599 } … … 635 605 off_t pos = (off_t)IPC_GET_ARG3(*request); 636 606 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 607 fat_bs_t *bs; 637 608 size_t bytes; 638 block_t *b , *bb;609 block_t *b; 639 610 uint16_t bps; 640 611 unsigned spc; … … 671 642 bytes = min(len, bps - pos % bps); 672 643 673 b b = block_get(dev_handle, BS_BLOCK, BS_SIZE);674 bps = uint16_t_le2host( FAT_BS(bb)->bps);675 spc = FAT_BS(bb)->spc;644 bs = block_bb_get(dev_handle); 645 bps = uint16_t_le2host(bs->bps); 646 spc = bs->spc; 676 647 677 648 boundary = ROUND_UP(nodep->size, bps * spc); … … 683 654 * next block size boundary. 684 655 */ 685 fat_fill_gap(b b->data, nodep, FAT_CLST_RES0, pos);686 b = fat_block_get(b b->data, nodep, pos / bps);656 fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos); 657 b = fat_block_get(bs, nodep, pos / bps); 687 658 (void) ipc_data_write_finalize(callid, b->data + pos % bps, 688 659 bytes); … … 694 665 } 695 666 fat_node_put(nodep); 696 block_put(bb);697 667 ipc_answer_1(rid, EOK, bytes); 698 668 return; … … 709 679 bps * spc; 710 680 /* create an independent chain of nclsts clusters in all FATs */ 711 status = fat_alloc_clusters(b b->data, dev_handle, nclsts, &mcl,681 status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, 712 682 &lcl); 713 683 if (status != EOK) { 714 684 /* could not allocate a chain of nclsts clusters */ 715 685 fat_node_put(nodep); 716 block_put(bb);717 686 ipc_answer_0(callid, status); 718 687 ipc_answer_0(rid, status); … … 720 689 } 721 690 /* zero fill any gaps */ 722 fat_fill_gap(b b->data, nodep, mcl, pos);723 b = _fat_block_get(b b->data, dev_handle, lcl,691 fat_fill_gap(bs, nodep, mcl, pos); 692 b = _fat_block_get(bs, dev_handle, lcl, 724 693 (pos / bps) % spc); 725 694 (void) ipc_data_write_finalize(callid, b->data + pos % bps, … … 731 700 * node's cluster chain. 732 701 */ 733 fat_append_clusters(b b->data, nodep, mcl);702 fat_append_clusters(bs, nodep, mcl); 734 703 nodep->size = pos + bytes; 735 704 nodep->dirty = true; /* need to sync node */ 736 705 fat_node_put(nodep); 737 block_put(bb);738 706 ipc_answer_1(rid, EOK, bytes); 739 707 return;
Note:
See TracChangeset
for help on using the changeset viewer.