Changeset 0b749a3 in mainline for uspace/srv/fs/fat/fat_fat.c
- Timestamp:
- 2010-11-22T15:39:53Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eddb76, aae339e9
- Parents:
- 9a1d8ab (diff), 8cd1aa5e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r9a1d8ab r0b749a3 70 70 * 71 71 * @param bs Buffer holding the boot sector for the file. 72 * @param dev _handle Device handle of the device with the file.72 * @param devmap_handle Device handle of the device with the file. 73 73 * @param firstc First cluster to start the walk with. 74 74 * @param lastc If non-NULL, output argument hodling the last cluster … … 81 81 */ 82 82 int 83 fat_cluster_walk(fat_bs_t *bs, dev _handle_t dev_handle, fat_cluster_t firstc,83 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc, 84 84 fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters) 85 85 { … … 108 108 fidx = clst % (BPS(bs) / sizeof(fat_cluster_t)); 109 109 /* read FAT1 */ 110 rc = block_get(&b, dev _handle, RSCNT(bs) + fsec,110 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec, 111 111 BLOCK_FLAGS_NONE); 112 112 if (rc != EOK) … … 159 159 * when fortunately we have the last cluster number cached. 160 160 */ 161 return block_get(block, nodep->idx->dev _handle,161 return block_get(block, nodep->idx->devmap_handle, 162 162 CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags); 163 163 } … … 173 173 174 174 fall_through: 175 rc = _fat_block_get(block, bs, nodep->idx->dev _handle, firstc,175 rc = _fat_block_get(block, bs, nodep->idx->devmap_handle, firstc, 176 176 &currc, relbn, flags); 177 177 if (rc != EOK) … … 192 192 * @param block Pointer to a block pointer for storing result. 193 193 * @param bs Buffer holding the boot sector of the file system. 194 * @param dev _handle Device handle of the file system.194 * @param devmap_handle Device handle of the file system. 195 195 * @param fcl First cluster used by the file. Can be zero if the file 196 196 * is empty. … … 204 204 */ 205 205 int 206 _fat_block_get(block_t **block, fat_bs_t *bs, dev _handle_t dev_handle,206 _fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle, 207 207 fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags) 208 208 { … … 221 221 /* root directory special case */ 222 222 assert(bn < RDS(bs)); 223 rc = block_get(block, dev _handle,223 rc = block_get(block, devmap_handle, 224 224 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags); 225 225 return rc; … … 227 227 228 228 max_clusters = bn / SPC(bs); 229 rc = fat_cluster_walk(bs, dev _handle, fcl, &c, &clusters, max_clusters);229 rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters); 230 230 if (rc != EOK) 231 231 return rc; 232 232 assert(clusters == max_clusters); 233 233 234 rc = block_get(block, dev _handle, CLBN2PBN(bs, c, bn), flags);234 rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags); 235 235 236 236 if (clp) … … 280 280 /* zero out the initial part of the new cluster chain */ 281 281 for (o = boundary; o < pos; o += BPS(bs)) { 282 rc = _fat_block_get(&b, bs, nodep->idx->dev _handle, mcl,282 rc = _fat_block_get(&b, bs, nodep->idx->devmap_handle, mcl, 283 283 NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD); 284 284 if (rc != EOK) … … 297 297 * 298 298 * @param bs Buffer holding the boot sector for the file system. 299 * @param dev _handle Device handle for the file system.299 * @param devmap_handle Device handle for the file system. 300 300 * @param clst Cluster which to get. 301 301 * @param value Output argument holding the value of the cluster. … … 304 304 */ 305 305 int 306 fat_get_cluster(fat_bs_t *bs, dev _handle_t dev_handle, unsigned fatno,306 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 307 307 fat_cluster_t clst, fat_cluster_t *value) 308 308 { … … 311 311 int rc; 312 312 313 rc = block_get(&b, dev _handle, RSCNT(bs) + SF(bs) * fatno +313 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 314 314 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 315 315 if (rc != EOK) … … 326 326 * 327 327 * @param bs Buffer holding the boot sector for the file system. 328 * @param dev _handle Device handle for the file system.328 * @param devmap_handle Device handle for the file system. 329 329 * @param fatno Number of the FAT instance where to make the change. 330 330 * @param clst Cluster which is to be set. … … 334 334 */ 335 335 int 336 fat_set_cluster(fat_bs_t *bs, dev _handle_t dev_handle, unsigned fatno,336 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 337 337 fat_cluster_t clst, fat_cluster_t value) 338 338 { … … 342 342 343 343 assert(fatno < FATCNT(bs)); 344 rc = block_get(&b, dev _handle, RSCNT(bs) + SF(bs) * fatno +344 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 345 345 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 346 346 if (rc != EOK) … … 357 357 * 358 358 * @param bs Buffer holding the boot sector of the file system. 359 * @param dev _handle Device handle of the file system.359 * @param devmap_handle Device handle of the file system. 360 360 * @param lifo Chain of allocated clusters. 361 361 * @param nclsts Number of clusters in the lifo chain. … … 363 363 * @return EOK on success or a negative error code. 364 364 */ 365 int fat_alloc_shadow_clusters(fat_bs_t *bs, dev _handle_t dev_handle,365 int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, 366 366 fat_cluster_t *lifo, unsigned nclsts) 367 367 { … … 372 372 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 373 373 for (c = 0; c < nclsts; c++) { 374 rc = fat_set_cluster(bs, dev _handle, fatno, lifo[c],374 rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c], 375 375 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 376 376 if (rc != EOK) … … 390 390 * 391 391 * @param bs Buffer holding the boot sector of the file system. 392 * @param dev _handle Device handle of the file system.392 * @param devmap_handle Device handle of the file system. 393 393 * @param nclsts Number of clusters to allocate. 394 394 * @param mcl Output parameter where the first cluster in the chain … … 400 400 */ 401 401 int 402 fat_alloc_clusters(fat_bs_t *bs, dev _handle_t dev_handle, unsigned nclsts,402 fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts, 403 403 fat_cluster_t *mcl, fat_cluster_t *lcl) 404 404 { … … 418 418 fibril_mutex_lock(&fat_alloc_lock); 419 419 for (b = 0, cl = 0; b < SF(bs); b++) { 420 rc = block_get(&blk, dev _handle, RSCNT(bs) + b,420 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b, 421 421 BLOCK_FLAGS_NONE); 422 422 if (rc != EOK) … … 424 424 for (c = 0; c < BPS(bs) / sizeof(fat_cluster_t); c++, cl++) { 425 425 /* 426 * Check if the cluster is physically there. This check 427 * becomes necessary when the file system is created 428 * with fewer total sectors than how many is inferred 429 * from the size of the file allocation table. 426 * Check if the entire cluster is physically there. 427 * This check becomes necessary when the file system is 428 * created with fewer total sectors than how many is 429 * inferred from the size of the file allocation table 430 * or when the last cluster ends beyond the end of the 431 * device. 430 432 */ 431 if ((cl >= 2) &&432 ((cl - 2) * SPC(bs) + SSA(bs) >= TS(bs))) {433 if ((cl >= FAT_CLST_FIRST) && 434 CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) { 433 435 rc = block_put(blk); 434 436 if (rc != EOK) … … 455 457 /* update the shadow copies of FAT */ 456 458 rc = fat_alloc_shadow_clusters(bs, 457 dev _handle, lifo, nclsts);459 devmap_handle, lifo, nclsts); 458 460 if (rc != EOK) 459 461 goto error; … … 482 484 */ 483 485 while (found--) { 484 rc = fat_set_cluster(bs, dev _handle, FAT1, lifo[found],486 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found], 485 487 FAT_CLST_RES0); 486 488 if (rc != EOK) { … … 497 499 * 498 500 * @param bs Buffer hodling the boot sector of the file system. 499 * @param dev _handle Device handle of the file system.501 * @param devmap_handle Device handle of the file system. 500 502 * @param firstc First cluster in the chain which is to be freed. 501 503 * … … 503 505 */ 504 506 int 505 fat_free_clusters(fat_bs_t *bs, dev _handle_t dev_handle, fat_cluster_t firstc)507 fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc) 506 508 { 507 509 unsigned fatno; … … 512 514 while (firstc < FAT_CLST_LAST1) { 513 515 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 514 rc = fat_get_cluster(bs, dev _handle, FAT1, firstc, &nextc);516 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc); 515 517 if (rc != EOK) 516 518 return rc; 517 519 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 518 rc = fat_set_cluster(bs, dev _handle, fatno, firstc,520 rc = fat_set_cluster(bs, devmap_handle, fatno, firstc, 519 521 FAT_CLST_RES0); 520 522 if (rc != EOK) … … 541 543 fat_cluster_t lcl) 542 544 { 543 dev _handle_t dev_handle = nodep->idx->dev_handle;545 devmap_handle_t devmap_handle = nodep->idx->devmap_handle; 544 546 fat_cluster_t lastc; 545 uint16_t numc;546 547 uint8_t fatno; 547 548 int rc; 548 549 549 if (nodep->lastc_cached_valid) { 550 lastc = nodep->lastc_cached_value; 551 nodep->lastc_cached_valid = false; 550 if (nodep->firstc == FAT_CLST_RES0) { 551 /* No clusters allocated to the node yet. */ 552 nodep->firstc = mcl; 553 nodep->dirty = true; /* need to sync node */ 552 554 } else { 553 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lastc, 554 &numc, (uint16_t) -1); 555 if (rc != EOK) 556 return rc; 557 558 if (numc == 0) { 559 /* No clusters allocated to the node yet. */ 560 nodep->firstc = mcl; 561 nodep->dirty = true; /* need to sync node */ 562 return EOK; 555 if (nodep->lastc_cached_valid) { 556 lastc = nodep->lastc_cached_value; 557 nodep->lastc_cached_valid = false; 558 } else { 559 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 560 &lastc, NULL, (uint16_t) -1); 561 if (rc != EOK) 562 return rc; 563 563 } 564 } 565 566 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {567 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lastc,568 mcl);569 if (rc != EOK)570 return rc;564 565 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 566 rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno, 567 lastc, mcl); 568 if (rc != EOK) 569 return rc; 570 } 571 571 } 572 572 … … 590 590 { 591 591 int rc; 592 dev _handle_t dev_handle = nodep->idx->dev_handle;592 devmap_handle_t devmap_handle = nodep->idx->devmap_handle; 593 593 594 594 /* … … 601 601 if (lcl == FAT_CLST_RES0) { 602 602 /* The node will have zero size and no clusters allocated. */ 603 rc = fat_free_clusters(bs, dev _handle, nodep->firstc);603 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc); 604 604 if (rc != EOK) 605 605 return rc; … … 610 610 unsigned fatno; 611 611 612 rc = fat_get_cluster(bs, dev _handle, FAT1, lcl, &nextc);612 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc); 613 613 if (rc != EOK) 614 614 return rc; … … 616 616 /* Terminate the cluster chain in all copies of FAT. */ 617 617 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 618 rc = fat_set_cluster(bs, dev _handle, fatno, lcl,618 rc = fat_set_cluster(bs, devmap_handle, fatno, lcl, 619 619 FAT_CLST_LAST1); 620 620 if (rc != EOK) … … 623 623 624 624 /* Free all following clusters. */ 625 rc = fat_free_clusters(bs, dev _handle, nextc);625 rc = fat_free_clusters(bs, devmap_handle, nextc); 626 626 if (rc != EOK) 627 627 return rc; … … 638 638 639 639 int 640 fat_zero_cluster(struct fat_bs *bs, dev _handle_t dev_handle, fat_cluster_t c)640 fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c) 641 641 { 642 642 int i; … … 645 645 646 646 for (i = 0; i < SPC(bs); i++) { 647 rc = _fat_block_get(&b, bs, dev _handle, c, NULL, i,647 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i, 648 648 BLOCK_FLAGS_NOREAD); 649 649 if (rc != EOK) … … 665 665 * does not contain a fat file system. 666 666 */ 667 int fat_sanity_check(fat_bs_t *bs, dev _handle_t dev_handle)667 int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle) 668 668 { 669 669 fat_cluster_t e0, e1; … … 706 706 707 707 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 708 rc = fat_get_cluster(bs, dev _handle, fat_no, 0, &e0);708 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0); 709 709 if (rc != EOK) 710 710 return EIO; 711 711 712 rc = fat_get_cluster(bs, dev _handle, fat_no, 1, &e1);712 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1); 713 713 if (rc != EOK) 714 714 return EIO;
Note:
See TracChangeset
for help on using the changeset viewer.