Changeset db6e419 in mainline for uspace/srv/fs/fat/fat_fat.c
- Timestamp:
- 2011-08-16T18:53:00Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 49160c4
- Parents:
- e0e922d (diff), 45058baa (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
re0e922d rdb6e419 71 71 * 72 72 * @param bs Buffer holding the boot sector for the file. 73 * @param devmap_handle Device handleof the device with the file.73 * @param service_id Service ID of the device with the file. 74 74 * @param firstc First cluster to start the walk with. 75 75 * @param lastc If non-NULL, output argument hodling the last cluster … … 82 82 */ 83 83 int 84 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc,84 fat_cluster_walk(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc, 85 85 fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters) 86 86 { … … 109 109 fidx = clst % (BPS(bs) / sizeof(fat_cluster_t)); 110 110 /* read FAT1 */ 111 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,111 rc = block_get(&b, service_id, RSCNT(bs) + fsec, 112 112 BLOCK_FLAGS_NONE); 113 113 if (rc != EOK) … … 160 160 * when fortunately we have the last cluster number cached. 161 161 */ 162 return block_get(block, nodep->idx-> devmap_handle,162 return block_get(block, nodep->idx->service_id, 163 163 CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags); 164 164 } … … 174 174 175 175 fall_through: 176 rc = _fat_block_get(block, bs, nodep->idx-> devmap_handle, firstc,176 rc = _fat_block_get(block, bs, nodep->idx->service_id, firstc, 177 177 &currc, relbn, flags); 178 178 if (rc != EOK) … … 193 193 * @param block Pointer to a block pointer for storing result. 194 194 * @param bs Buffer holding the boot sector of the file system. 195 * @param devmap_handle Devicehandle of the file system.195 * @param service_id Service ID handle of the file system. 196 196 * @param fcl First cluster used by the file. Can be zero if the file 197 197 * is empty. … … 205 205 */ 206 206 int 207 _fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle,207 _fat_block_get(block_t **block, fat_bs_t *bs, service_id_t service_id, 208 208 fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags) 209 209 { … … 222 222 /* root directory special case */ 223 223 assert(bn < RDS(bs)); 224 rc = block_get(block, devmap_handle,224 rc = block_get(block, service_id, 225 225 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags); 226 226 return rc; … … 228 228 229 229 max_clusters = bn / SPC(bs); 230 rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters);230 rc = fat_cluster_walk(bs, service_id, fcl, &c, &clusters, max_clusters); 231 231 if (rc != EOK) 232 232 return rc; 233 233 assert(clusters == max_clusters); 234 234 235 rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags);235 rc = block_get(block, service_id, CLBN2PBN(bs, c, bn), flags); 236 236 237 237 if (clp) … … 281 281 /* zero out the initial part of the new cluster chain */ 282 282 for (o = boundary; o < pos; o += BPS(bs)) { 283 rc = _fat_block_get(&b, bs, nodep->idx-> devmap_handle, mcl,283 rc = _fat_block_get(&b, bs, nodep->idx->service_id, mcl, 284 284 NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD); 285 285 if (rc != EOK) … … 298 298 * 299 299 * @param bs Buffer holding the boot sector for the file system. 300 * @param devmap_handle Device handlefor the file system.300 * @param service_id Service ID for the file system. 301 301 * @param clst Cluster which to get. 302 302 * @param value Output argument holding the value of the cluster. … … 305 305 */ 306 306 int 307 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,307 fat_get_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno, 308 308 fat_cluster_t clst, fat_cluster_t *value) 309 309 { … … 312 312 int rc; 313 313 314 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +314 rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno + 315 315 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 316 316 if (rc != EOK) … … 327 327 * 328 328 * @param bs Buffer holding the boot sector for the file system. 329 * @param devmap_handle Device handlefor the file system.329 * @param service_id Device service ID for the file system. 330 330 * @param fatno Number of the FAT instance where to make the change. 331 331 * @param clst Cluster which is to be set. … … 335 335 */ 336 336 int 337 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,337 fat_set_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno, 338 338 fat_cluster_t clst, fat_cluster_t value) 339 339 { … … 343 343 344 344 assert(fatno < FATCNT(bs)); 345 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +345 rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno + 346 346 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 347 347 if (rc != EOK) … … 358 358 * 359 359 * @param bs Buffer holding the boot sector of the file system. 360 * @param devmap_handle Device handleof the file system.360 * @param service_id Service ID of the file system. 361 361 * @param lifo Chain of allocated clusters. 362 362 * @param nclsts Number of clusters in the lifo chain. … … 364 364 * @return EOK on success or a negative error code. 365 365 */ 366 int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle,366 int fat_alloc_shadow_clusters(fat_bs_t *bs, service_id_t service_id, 367 367 fat_cluster_t *lifo, unsigned nclsts) 368 368 { … … 373 373 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 374 374 for (c = 0; c < nclsts; c++) { 375 rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],375 rc = fat_set_cluster(bs, service_id, fatno, lifo[c], 376 376 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 377 377 if (rc != EOK) … … 391 391 * 392 392 * @param bs Buffer holding the boot sector of the file system. 393 * @param devmap_handle Device handleof the file system.393 * @param service_id Device service ID of the file system. 394 394 * @param nclsts Number of clusters to allocate. 395 395 * @param mcl Output parameter where the first cluster in the chain … … 401 401 */ 402 402 int 403 fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts,403 fat_alloc_clusters(fat_bs_t *bs, service_id_t service_id, unsigned nclsts, 404 404 fat_cluster_t *mcl, fat_cluster_t *lcl) 405 405 { … … 419 419 fibril_mutex_lock(&fat_alloc_lock); 420 420 for (b = 0, cl = 0; b < SF(bs); b++) { 421 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,421 rc = block_get(&blk, service_id, RSCNT(bs) + b, 422 422 BLOCK_FLAGS_NONE); 423 423 if (rc != EOK) … … 458 458 /* update the shadow copies of FAT */ 459 459 rc = fat_alloc_shadow_clusters(bs, 460 devmap_handle, lifo, nclsts);460 service_id, lifo, nclsts); 461 461 if (rc != EOK) 462 462 goto error; … … 485 485 */ 486 486 while (found--) { 487 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],487 rc = fat_set_cluster(bs, service_id, FAT1, lifo[found], 488 488 FAT_CLST_RES0); 489 489 if (rc != EOK) { … … 500 500 * 501 501 * @param bs Buffer hodling the boot sector of the file system. 502 * @param devmap_handle Device handleof the file system.502 * @param service_id Device service ID of the file system. 503 503 * @param firstc First cluster in the chain which is to be freed. 504 504 * … … 506 506 */ 507 507 int 508 fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc)508 fat_free_clusters(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc) 509 509 { 510 510 unsigned fatno; … … 515 515 while (firstc < FAT_CLST_LAST1) { 516 516 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 517 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);517 rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc); 518 518 if (rc != EOK) 519 519 return rc; 520 520 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 521 rc = fat_set_cluster(bs, devmap_handle, fatno, firstc,521 rc = fat_set_cluster(bs, service_id, fatno, firstc, 522 522 FAT_CLST_RES0); 523 523 if (rc != EOK) … … 544 544 fat_cluster_t lcl) 545 545 { 546 devmap_handle_t devmap_handle = nodep->idx->devmap_handle;546 service_id_t service_id = nodep->idx->service_id; 547 547 fat_cluster_t lastc; 548 548 uint8_t fatno; … … 558 558 nodep->lastc_cached_valid = false; 559 559 } else { 560 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,560 rc = fat_cluster_walk(bs, service_id, nodep->firstc, 561 561 &lastc, NULL, (uint16_t) -1); 562 562 if (rc != EOK) … … 565 565 566 566 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 567 rc = fat_set_cluster(bs, nodep->idx-> devmap_handle, fatno,567 rc = fat_set_cluster(bs, nodep->idx->service_id, fatno, 568 568 lastc, mcl); 569 569 if (rc != EOK) … … 591 591 { 592 592 int rc; 593 devmap_handle_t devmap_handle = nodep->idx->devmap_handle;593 service_id_t service_id = nodep->idx->service_id; 594 594 595 595 /* … … 602 602 if (lcl == FAT_CLST_RES0) { 603 603 /* The node will have zero size and no clusters allocated. */ 604 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc);604 rc = fat_free_clusters(bs, service_id, nodep->firstc); 605 605 if (rc != EOK) 606 606 return rc; … … 611 611 unsigned fatno; 612 612 613 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc);613 rc = fat_get_cluster(bs, service_id, FAT1, lcl, &nextc); 614 614 if (rc != EOK) 615 615 return rc; … … 617 617 /* Terminate the cluster chain in all copies of FAT. */ 618 618 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 619 rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,619 rc = fat_set_cluster(bs, service_id, fatno, lcl, 620 620 FAT_CLST_LAST1); 621 621 if (rc != EOK) … … 624 624 625 625 /* Free all following clusters. */ 626 rc = fat_free_clusters(bs, devmap_handle, nextc);626 rc = fat_free_clusters(bs, service_id, nextc); 627 627 if (rc != EOK) 628 628 return rc; … … 639 639 640 640 int 641 fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c)641 fat_zero_cluster(struct fat_bs *bs, service_id_t service_id, fat_cluster_t c) 642 642 { 643 643 int i; … … 646 646 647 647 for (i = 0; i < SPC(bs); i++) { 648 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i,648 rc = _fat_block_get(&b, bs, service_id, c, NULL, i, 649 649 BLOCK_FLAGS_NOREAD); 650 650 if (rc != EOK) … … 666 666 * does not contain a fat file system. 667 667 */ 668 int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle)668 int fat_sanity_check(fat_bs_t *bs, service_id_t service_id) 669 669 { 670 670 fat_cluster_t e0, e1; … … 707 707 708 708 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 709 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);709 rc = fat_get_cluster(bs, service_id, fat_no, 0, &e0); 710 710 if (rc != EOK) 711 711 return EIO; 712 712 713 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);713 rc = fat_get_cluster(bs, service_id, fat_no, 1, &e1); 714 714 if (rc != EOK) 715 715 return EIO;
Note:
See TracChangeset
for help on using the changeset viewer.